forked from science-ation/science-ation
Updated super/conferences to properly manage existing conferences, and touched up it's UI to fit the site theme
This commit is contained in:
parent
63178e596b
commit
0720cb0ae0
@ -123,9 +123,83 @@ if(array_key_exists('formAction', $_POST)){
|
||||
// check for an action by the normal method
|
||||
if(array_key_exists('action', $_GET)){
|
||||
switch($_GET['action']){
|
||||
case 'new': // this is a request to create a new conference
|
||||
case 'loadTable':
|
||||
draw_conferences_list();
|
||||
break;
|
||||
case 'new':
|
||||
// present them with a wizard in which to create a new conference
|
||||
$_SESSION['conference_wizard'] = array();
|
||||
wizard_draw_step('start');
|
||||
break;
|
||||
case 'edit':
|
||||
// give them an editor in which to modify an existing conference
|
||||
$cid = $_POST['id'];
|
||||
if(is_numeric($cid)){
|
||||
$conf = mysql_fetch_assoc(mysql_query("SELECT * FROM conferences WHERE id = $cid"));
|
||||
if(is_array($conf)){
|
||||
echo "<table>";
|
||||
echo "<tr><td>" . i18n('Name') . ":</td><td><input type=\"text\" id=\"confName\" value=\"{$conf['name']}\"></input></td></tr>";
|
||||
echo "<tr><td>" . i18n('Conference Type') . ":</td><td>";
|
||||
echo "<select id=\"confType\">";
|
||||
echo "<option value=\"sciencefair\""; if($conf['type'] == 'sciencefair') echo " SELECTED"; echo ">" . i18n("Science Fair") . "</option>";
|
||||
echo "<option value=\"scienceolympics\""; if($conf['type'] == 'scienceolympics') echo " SELECTED"; echo ">" . i18n("Science Olympics") . "</option>";
|
||||
echo "</select>";
|
||||
echo "</td></tr>";
|
||||
echo "<tr><td>" . i18n('Status') . ":</td><td>";
|
||||
$statuses = array('pending','running','ended');
|
||||
echo "<select id=\"confStatus\">";
|
||||
foreach($statuses as $status){
|
||||
echo "<option value=\"$status\"";
|
||||
if($conf['status'] == $status) echo " SELECTED";
|
||||
echo ">$status</option>";
|
||||
}
|
||||
echo "</select>";
|
||||
|
||||
echo "</td></tr>";
|
||||
echo "</table>";
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'save':
|
||||
// save the new conference data for the conference that's being edited
|
||||
$confId = $_POST['id'];
|
||||
if(!is_numeric($confId)){
|
||||
error_("invalid conference id");
|
||||
}
|
||||
// verify that the specified conference already exists
|
||||
$countRecord = mysql_fetch_assoc(mysql_query("SELECT COUNT(*) as tally FROM conferences WHERE id = $confId"), 0);
|
||||
$tally = $countRecord['tally'];
|
||||
if($tally == 1){
|
||||
// ok, it's a valid conference id. Let's go ahead and update the data for it
|
||||
$confType = mysql_real_escape_string($_POST['confType']);
|
||||
$confName = mysql_real_escape_string($_POST['confName']);
|
||||
$confStatus = mysql_real_escape_string($_POST['confStatus']);
|
||||
mysql_query("UPDATE conferences SET type='$confType', name='$confName', status='$confStatus' WHERE id='$confId'");
|
||||
$errMsg = mysql_error();
|
||||
if($errMsg != null){
|
||||
error_("SQL error: $errMsg");
|
||||
}else{
|
||||
happy_("Conference updated successfully");
|
||||
}
|
||||
}else{
|
||||
error_("nonexistant conference id");
|
||||
}
|
||||
break;
|
||||
case 'delete':
|
||||
// delete the specified conference
|
||||
$confId = $_POST['id'];
|
||||
if(!is_numeric($confId)){
|
||||
error_("invalid conference id");
|
||||
}else{
|
||||
mysql_query("UPDATE conferences set status='deleted' WHERE id = $confId");
|
||||
$errMsg = mysql_error();
|
||||
if($errMsg != null){
|
||||
error_("SQL error: $errMsg");
|
||||
}else{
|
||||
happy_("Conference updated successfully");
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
exit;
|
||||
@ -139,29 +213,67 @@ send_header("Conferences Setup",
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
var wizard;
|
||||
$(document).ready(function() {
|
||||
// $('#wizardBackdrop').fadeTo(0, 0);
|
||||
|
||||
});
|
||||
|
||||
function editConference(cid){
|
||||
alert('edit ' + cid);
|
||||
var editor = $('<div></div>');
|
||||
$.post('conferences.php?action=edit', {'id':cid}, function(result){
|
||||
editor.html(result);
|
||||
editor.dialog({
|
||||
'title':'<?=i18n("Edit")?>',
|
||||
'modal':'true',
|
||||
'buttons':{
|
||||
'<?=i18n('Cancel')?>':function(){
|
||||
editor.dialog('close');
|
||||
editor.remove();
|
||||
},
|
||||
'<?=i18n('Ok')?>':function(){
|
||||
$.post(
|
||||
'conferences.php?action=save',
|
||||
{
|
||||
'id':cid,
|
||||
'confStatus':$('#confStatus').val(),
|
||||
'confType':$('#confType').val(),
|
||||
'confName':$('#confName').val()
|
||||
},
|
||||
function(result){
|
||||
editor.dialog('close');
|
||||
editor.remove();
|
||||
$('#conferences').load('conferences.php?action=loadTable');
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function dropConference(cid){
|
||||
alert('drop ' + cid);
|
||||
var confirmation = $('<div></div>');
|
||||
confirmation.append('<?=i18n("Are you sure you want to delete this conference?");?>');
|
||||
confirmation.dialog({
|
||||
'title': '<?=i18n("Are you sure");?>',
|
||||
'modal': true,
|
||||
'buttons':{
|
||||
'<?=i18n('No')?>':function(){
|
||||
$(this).dialog('close');
|
||||
$(this).remove();
|
||||
},
|
||||
'<?=i18n('Yes')?>':function(){
|
||||
$(this).dialog('close');
|
||||
$.post('conferences.php?action=delete', {'id':cid}, function(result){
|
||||
$('#conferences').load('conferences.php?action=loadTable');
|
||||
});
|
||||
$(this).remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function openWizard(){
|
||||
$('#addAnchor').hide();
|
||||
/*
|
||||
$('#wizardWrapper').css({'display':'block'});
|
||||
$('#wizardBackdrop').css({'display':'block'});
|
||||
$('#wizardBackdrop').fadeTo('slow', 0.8);
|
||||
*/
|
||||
wizard = $('<div></div>');
|
||||
$('#conferences').append(wizard);
|
||||
wizard.dialog();
|
||||
wizard.dialog({'modal':'true'});
|
||||
wizard.load('conferences.php?action=new');
|
||||
}
|
||||
|
||||
@ -195,43 +307,37 @@ function handleSubmit(action){
|
||||
|
||||
</script>
|
||||
|
||||
<a href='' onclick="openWizard(); return false;">Add a conference</a>
|
||||
<hr/>
|
||||
<div id="conferences">
|
||||
<?php draw_conferences_list(); ?>
|
||||
<br/>
|
||||
<hr/>
|
||||
<a id="addAnchor" href='' onclick="openWizard(); return false;">Add a conference</a>
|
||||
</div>
|
||||
<?
|
||||
send_footer();
|
||||
|
||||
function draw_conferences_list(){
|
||||
echo "<table>";
|
||||
$query = mysql_query("SELECT * FROM `conferences`");
|
||||
echo "<table class=\"summarytable\">";
|
||||
echo "<thead><tr><th colspan=\"5\">" . i18n("Conferences") . "</th></tr></thead>";
|
||||
$query = mysql_query("SELECT * FROM `conferences` WHERE status <> 'deleted'");
|
||||
$rowNumbr = 0;
|
||||
while($row = mysql_fetch_assoc($query)){
|
||||
echo "<tr>";
|
||||
echo '<tr class="';
|
||||
if(($rowNumber++) % 2) echo 'odd';
|
||||
else echo 'even';
|
||||
echo '">';
|
||||
echo "<td>{$row['name']}</td><td>{$row['type']}</td><td>{$row['status']}</td>";
|
||||
echo "<td><button onclick=\"editConference({$row['id']});return false;\">" . i18n("Edit") . " <img src=\"/icons/16/edit.png\"/></button></td>";
|
||||
echo "<td><button onclick=\"dropConference({$row['id']});return false;\">" . i18n("Delete") . " <img src=\"/icons/16/button_cancel.png\"/></button></td>";
|
||||
echo "<td><img onclick=\"editConference({$row['id']});return false;\" alt=\"" . i18n("Edit") . "\" src=\"/icons/16/edit.png\"/></td>";
|
||||
if($row['status'] == 'running'){
|
||||
echo "<td></td>"; // can't delete a running conference
|
||||
}else{
|
||||
echo "<td><img onclick=\"dropConference({$row['id']});return false;\" alt=\"" . i18n("Delete") . "\" src=\"/icons/16/button_cancel.png\"/></td>";
|
||||
}
|
||||
echo "</tr>";
|
||||
}
|
||||
echo "</table>";
|
||||
}
|
||||
/*
|
||||
require("../tableeditor.class.php");
|
||||
|
||||
$editor=new TableEditor("conferences",
|
||||
array(
|
||||
"name"=>"Conference Name",
|
||||
"type"=>"Type",
|
||||
"status"=>"Status"
|
||||
)
|
||||
);
|
||||
|
||||
$editor->setPrimaryKey("id");
|
||||
$editor->setDefaultSortField("id");
|
||||
$editor->setRecordType("Conference");
|
||||
$editor->execute();
|
||||
*/
|
||||
/************** Wizard handling functions *************/
|
||||
// draw an individual step in the wizard
|
||||
function wizard_draw_step($step, $message = null){
|
||||
@ -281,7 +387,7 @@ function wizard_close(){
|
||||
echo "
|
||||
<script type=\"text/javascript\">
|
||||
wizard.dialog('close');
|
||||
$('#addAnchor').show();
|
||||
wizard.remove();
|
||||
</script>
|
||||
";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user