forked from science-ation/science-ation
Add a "new project" feature.
This commit is contained in:
parent
4739e3fdf0
commit
f695306f92
@ -69,15 +69,15 @@ case 'delete':
|
||||
?>
|
||||
|
||||
<div id="student_editor" title="Student/Project Editor" style="display: none">
|
||||
<div id="editor_tabs">
|
||||
<div id="editor_tabs" >
|
||||
<ul>
|
||||
<li><a href="#editor_tab_reg"><span><?=i18n('Registration')?></span></a></li>
|
||||
<li><a href="#editor_tab_students"><span><?=i18n('Students')?></span></a></li>
|
||||
<li><a href="#editor_tab_project"><span><?=i18n('Project')?></span></a></li>
|
||||
<li><a href="#editor_tab_reg"><span><?=i18n('Registration')?></span></a></li>
|
||||
</ul>
|
||||
<div id="editor_tab_reg">Loading...</div>
|
||||
<div id="editor_tab_students">Loading...</div>
|
||||
<div id="editor_tab_project">Loading...</div>
|
||||
<div id="editor_tab_reg">Loading...</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -85,12 +85,19 @@ case 'delete':
|
||||
<script language="javascript" type="text/javascript">
|
||||
|
||||
var registrations_id = 0;
|
||||
var registrations_new = 0;
|
||||
function popup_editor(id, open_tab)
|
||||
{
|
||||
var w = (document.documentElement.clientWidth * 0.8);
|
||||
var h = (document.documentElement.clientHeight * 0.8);
|
||||
var w = (document.documentElement.clientWidth * 0.9);
|
||||
var h = (document.documentElement.clientHeight * 0.9);
|
||||
|
||||
registrations_id = id;
|
||||
registrations_new = 0;
|
||||
|
||||
if(id == -1) {
|
||||
open_tab = 'reg';
|
||||
registrations_new = 1;
|
||||
}
|
||||
|
||||
/* Force no tabs to be selected, need to set collapsible
|
||||
* to true first */
|
||||
@ -99,13 +106,19 @@ function popup_editor(id, open_tab)
|
||||
|
||||
/* Then we'll select a tab to force a reload */
|
||||
switch(open_tab) {
|
||||
case 'projects':
|
||||
case 'reg':
|
||||
/* If we open on the reg tab, disable the others until a save */
|
||||
$('#editor_tabs').tabs('option', 'disabled', [1,2]);
|
||||
$('#editor_tabs').tabs('select', 0);
|
||||
break;
|
||||
|
||||
case 'project':
|
||||
$('#editor_tabs').tabs('option', 'disabled', []);
|
||||
$('#editor_tabs').tabs('select', 1);
|
||||
$('#editor_tabs').tabs('select', 2);
|
||||
break;
|
||||
default:
|
||||
$('#editor_tabs').tabs('option', 'disabled', []);
|
||||
$('#editor_tabs').tabs('select', 0);
|
||||
$('#editor_tabs').tabs('select', 1);
|
||||
break;
|
||||
}
|
||||
/* Don't let anything collapse */
|
||||
@ -207,7 +220,13 @@ function update_reg()
|
||||
/* Attach to save button */
|
||||
$("#registration_save").click(function() {
|
||||
var id = registrations_id;
|
||||
$("#debug").load("student_editor.php?action=registration_save&id="+id, $("#registration_form").serializeArray());
|
||||
$('#debug').load("student_editor.php?action=registration_save&id="+id, $("#registration_form").serializeArray());
|
||||
/* Enable the other tabs now after a save, FIXME: should be
|
||||
* after a successful save, but we should use on-the-fly form
|
||||
* validation to disable the save button, so the extra callback/error
|
||||
* check isn't needed */
|
||||
$('#editor_tabs').tabs('option', 'disabled', []);
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
@ -239,6 +258,10 @@ $(document).ready(function() {
|
||||
close: function() {
|
||||
/* Reload the row after the dialog close in case the info has changed */
|
||||
var id = registrations_id;
|
||||
if(registrations_new == true) {
|
||||
/* Create a row before loading it */
|
||||
$("#registration_list").append("<tr id=\"row_"+id+"\"></tr>");
|
||||
}
|
||||
$("#row_"+id).load("<?$_SERVER['PHP_SELF']?>?action=load_row&id="+id);
|
||||
$("#row_"+id).effect('highlight',{},500);
|
||||
}
|
||||
@ -263,38 +286,47 @@ $(document).ready(function() {
|
||||
},
|
||||
selected: 0
|
||||
});
|
||||
|
||||
$("#newproject").click(function() {
|
||||
popup_editor(-1);
|
||||
}
|
||||
);
|
||||
});
|
||||
</script>
|
||||
|
||||
<?
|
||||
echo "<br />";
|
||||
echo i18n("Choose Status").":";
|
||||
echo "<form name=\"statuschangerform\" method=\"get\" action=\"registration_list.php\">";
|
||||
echo "<select name=\"showstatus\" onchange=\"document.forms.statuschangerform.submit()\">";
|
||||
|
||||
$status_str = array();
|
||||
$status_str[''] = i18n("Any Status");
|
||||
$status_str['complete'] = i18n("Complete");
|
||||
<br />
|
||||
<table width="100%">
|
||||
<tr><td>
|
||||
<?=i18n("Choose Status")?>:
|
||||
<form name="statuschangerform" method="get" action="registration_list.php">
|
||||
<select name="showstatus" onchange="document.forms.statuschangerform.submit()">
|
||||
|
||||
<?
|
||||
//if there is no reg fee, then we dont need to show this status, because nobody will ever be in this status
|
||||
if($config['regfee']>0) $status_str['paymentpending'] = i18n("Payment Pending");
|
||||
$status_str['open'] = i18n("Open");
|
||||
$status_str['new'] = i18n("New");
|
||||
$status_str = array('' => 'Any Status', 'complete' => 'Complete',
|
||||
'paymentpending' => ($config['regfee']>0) ? 'Payment Pending' : '',
|
||||
'open' => 'Open', 'new' => 'New');
|
||||
|
||||
$showstatus = $_GET['showstatus'];
|
||||
|
||||
foreach($status_str as $s=>$str) {
|
||||
$sel = ($showstatus == $s) ? "selected=\"selected\"" : '';
|
||||
echo "<option $sel value=\"$s\">$str</option>\n";
|
||||
if($str == '') continue;
|
||||
$sel = ($showstatus == $s) ? "selected=\"selected\"" : '';
|
||||
echo "<option $sel value=\"$s\">".i18n($str)."</option>\n";
|
||||
}
|
||||
echo "</select>";
|
||||
echo "</form>";
|
||||
?>
|
||||
</select></form></td>
|
||||
<td align="right"><button id="newproject"><?=i18n("Create New Project")?></button></td>
|
||||
</tr></table>
|
||||
<?
|
||||
|
||||
if($showstatus) $wherestatus="AND status='$showstatus' ";
|
||||
else $wherestatus="";
|
||||
|
||||
$q = list_query($year, $wherestatus, $_GET['sort'], false);
|
||||
|
||||
echo "<table class=\"tableview\">";
|
||||
echo "<table id=\"registration_list\" class=\"tableview\">";
|
||||
echo "<tr>";
|
||||
if($showstatus) $stat="&showstatus=".$showstatus;
|
||||
echo "<th><a href=\"registration_list.php?sort=status$stat\">".i18n("Status")."</a></th>";
|
||||
@ -376,16 +408,15 @@ function print_row($r)
|
||||
|
||||
$status_text=i18n($status_text);
|
||||
|
||||
// $cl = ($r->award_source_fairs_id) ? externalaward : '';
|
||||
$scl = "style=\"cursor:pointer;\" onclick=\"popup_editor('{$r->reg_id}','');\"";
|
||||
$pcl = "style=\"cursor:pointer;\" onclick=\"popup_editor('{$r->reg_id}','projects');\"";
|
||||
$pcl = "style=\"cursor:pointer;\" onclick=\"popup_editor('{$r->reg_id}','project');\"";
|
||||
|
||||
echo "<td $scl>{$status_text}</td>";
|
||||
echo "<td $scl>{$r->email}</td>";
|
||||
echo "<td $scl>{$r->reg_num}</td>";
|
||||
$pn = str_replace(' ', ' ', $r->projectnumber);
|
||||
echo "<td $scl>$pn</td>";
|
||||
echo "<td $scl>{$r->title}</td>";
|
||||
echo "<td $pcl>{$r->title}</td>";
|
||||
|
||||
echo "<td $scl>".i18n($cats[$r->projectcategories_id])."</td>";
|
||||
echo "<td $scl>".i18n($divs[$r->projectdivisions_id])."</td>";
|
||||
|
@ -387,24 +387,37 @@ function registration_load()
|
||||
global $registrations_id, $config;
|
||||
|
||||
/* Load reg data */
|
||||
$q = mysql_query("SELECT * FROM registrations WHERE id='$registrations_id'");
|
||||
if(mysql_num_rows($q) != 1)
|
||||
$r = array();
|
||||
else {
|
||||
$r = mysql_fetch_assoc($q);
|
||||
/* Get the fair from the project */
|
||||
$q = mysql_query("SELECT fairs_id FROM projects WHERE registrations_id='$registrations_id'");
|
||||
if(mysql_num_rows($q) == 1) {
|
||||
$p = mysql_fetch_assoc($q);
|
||||
$r['fairs_id'] = $p['fairs_id'];
|
||||
}
|
||||
}
|
||||
if($registrations_id == -1) {
|
||||
/* New project */
|
||||
/* Find a reg num */
|
||||
do {
|
||||
$regnum=rand(100000,999999);
|
||||
$q=mysql_query("SELECT * FROM registrations WHERE num='$regnum' AND year={$config['FAIRYEAR']}");
|
||||
} while(mysql_num_rows($q)>0);
|
||||
|
||||
/* Load fairs */
|
||||
$fairs = array();
|
||||
$q = mysql_query("SELECT * FROM fairs WHERE type='feeder'");
|
||||
while(($f = mysql_fetch_assoc($q))) {
|
||||
$fairs[$f['id']] = $f;
|
||||
$r['num'] = $regnum;
|
||||
echo notice(i18n('New registration number generated.'));
|
||||
echo notice(i18n('This new registration will added when the "Save Registration Information" button is pressed below. At that time the other tabs will become available.'));
|
||||
} else {
|
||||
$q = mysql_query("SELECT * FROM registrations WHERE id='$registrations_id'");
|
||||
if(mysql_num_rows($q) != 1)
|
||||
$r = array();
|
||||
else {
|
||||
$r = mysql_fetch_assoc($q);
|
||||
/* Get the fair from the project */
|
||||
$q = mysql_query("SELECT fairs_id FROM projects WHERE registrations_id='$registrations_id'");
|
||||
if(mysql_num_rows($q) == 1) {
|
||||
$p = mysql_fetch_assoc($q);
|
||||
$r['fairs_id'] = $p['fairs_id'];
|
||||
}
|
||||
}
|
||||
|
||||
/* Load fairs */
|
||||
$fairs = array();
|
||||
$q = mysql_query("SELECT * FROM fairs WHERE type='feeder'");
|
||||
while(($f = mysql_fetch_assoc($q))) {
|
||||
$fairs[$f['id']] = $f;
|
||||
}
|
||||
}
|
||||
|
||||
/* Print form */
|
||||
@ -416,6 +429,9 @@ function registration_load()
|
||||
<tr>
|
||||
<td><?=i18n("Registration Number")?>:</td>
|
||||
<td><input type="text" name="registration_num" value="<?=$r['num']?>"></td>
|
||||
</tr><tr>
|
||||
<td><?=i18n("Registration Email")?>:</td>
|
||||
<td><input type="text" name="registration_email" value="<?=$r['email']?>"></td>
|
||||
</tr><tr>
|
||||
<td><?=i18n("Status")?>:</td>
|
||||
<td><select name="registration_status">
|
||||
@ -445,12 +461,27 @@ function registration_save()
|
||||
global $registrations_id, $config;
|
||||
$registration_num = intval($_POST['registration_num']);
|
||||
$registration_status = mysql_real_escape_string(stripslashes($_POST['registration_status']));
|
||||
$registration_email = mysql_real_escape_string(stripslashes($_POST['registration_email']));
|
||||
$fairs_id = intval($_POST['registration_fair']);
|
||||
|
||||
if($registrations_id == -1) {
|
||||
mysql_query("INSERT INTO registrations (start,schools_id,year) VALUES (
|
||||
NOW(), NULL, '{$config['FAIRYEAR']}')");
|
||||
$registrations_id = mysql_insert_id();
|
||||
|
||||
/* Create one student and a project */
|
||||
mysql_query("INSERT INTO students (registrations_id,email,year) VALUES (
|
||||
$registrations_id, '$registration_email', '{$config['FAIRYEAR']}')");
|
||||
mysql_query("INSERT INTO projects (registrations_id,year) VALUES (
|
||||
$registrations_id, '{$config['FAIRYEAR']}')");
|
||||
happy_('Created student and project record');
|
||||
}
|
||||
|
||||
/* Update registration */
|
||||
mysql_query("UPDATE registrations SET
|
||||
num='$registration_num',
|
||||
status='$registration_status'
|
||||
status='$registration_status',
|
||||
email='$registration_email'
|
||||
WHERE
|
||||
id='$registrations_id'");
|
||||
echo mysql_error();
|
||||
@ -462,6 +493,9 @@ function registration_save()
|
||||
registrations_id='$registrations_id'");
|
||||
echo mysql_error();
|
||||
happy_('Information Saved');
|
||||
echo "<script language=\"javascript\" type=\"text/javascript\">";
|
||||
echo "registrations_id=$registrations_id;";
|
||||
echo "</script>";
|
||||
}
|
||||
|
||||
?>
|
||||
|
Loading…
x
Reference in New Issue
Block a user