From f3f9e1c34262aaa2a816398cb18002cca1bd651f Mon Sep 17 00:00:00 2001 From: dave Date: Mon, 20 Apr 2009 04:33:49 +0000 Subject: [PATCH] - Updates for editting the fair --- fair_info.php | 43 +++++++++++++++++++++++++++++++++++++------ user.inc.php | 2 +- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/fair_info.php b/fair_info.php index a5156596..29d635ac 100644 --- a/fair_info.php +++ b/fair_info.php @@ -35,15 +35,28 @@ $u = user_load($_SESSION['users_id']); } + $fair_type = array('feeder' => 'Feeder Fair', 'sfiab' => 'SFIAB Upstream', 'ysf' => 'YSF/CWSF Upstream'); if($_POST['action']=="save") { - $fair_name = $_POST['fair_name']; - $fair_abbrv = $_POST['fair_abbrv']; + $id = $_POST['id']; + if(trim($id) == '') { + $q = mysql_query("INSERT INTO fairs(`id`,`name`) VALUES('','new entry')"); + $id = mysql_insert_id(); + } else { + $id = intval($id); + } - $u['fair_name'] = $fair_name; - $u['fair_abbrv'] = $fair_abbrv; + $name = mysql_escape_string(stripslashes($_POST['name'])); + $abbrv = mysql_escape_string(stripslashes($_POST['abbrv'])); + $url = mysql_escape_string($_POST['url']); + $type = array_key_exists($_POST['type'], $fair_type) ? $_POST['type'] : ''; + $q = mysql_query("UPDATE fairs SET `name`='$name', + `abbrv`='$abbrv', `url`='$url', + `type`='$type' WHERE id=$id"); + + $u['fairs_id'] = $id; user_save($u); message_push(notice(i18n("Fair Informaiton successfully updated"))); } @@ -71,15 +84,33 @@ if($_SESSION['embed'] == true) { array("Science Fair Main" => "fair_main.php") ); } + /* Load the fair info */ + $q = mysql_query("SELECT * FROM fairs WHERE id={$u['fairs_id']}"); + if(mysql_num_rows($q)) { + $f = mysql_fetch_assoc($q); + } else { + $f = array(); + } $s = ($_SESSION['embed'] == true) ? $_SESSION['embed_submit_url'] : 'fair_info.php'; echo "
\n"; echo "\n"; + echo "\n"; echo "\n"; echo '"; + echo '
'.i18n('Fair Name').''; - echo ""; + echo ""; echo '
'.i18n('Fair Abbreviation').''; - echo ""; + echo ""; + echo '
'.i18n('Fair Type').''; + echo "
'.i18n('URL').''; + if($f['url'] == '') $f['url'] = 'http://'; + echo ""; echo ''; echo "
"; diff --git a/user.inc.php b/user.inc.php index 9aa592fb..963cff58 100644 --- a/user.inc.php +++ b/user.inc.php @@ -310,7 +310,7 @@ function user_save_student($u) function user_save_fair($u) { - $fields = array('fair_active','fair_name','fair_abbrv'); + $fields = array('fair_active','fairs_id'); user_save_type_list($u, 'users_fair', $fields); }