Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • osian/sucs-site
  • kais58/sucs-site
  • imranh/sucs-site
  • foshjedi2004/sucs-site
  • gigosaurus/sucs-site
  • matstn/sucs-site
  • ripp_/sucs-site
  • eggnog/sucs-site
  • sucssite/sucs-site
  • elbows/sucs-site
  • realitykiller/sucs-site
  • crox/sucs-site
  • vectre/sucs-site
  • welshbyte/sucs-site
  • paperclipman/sucs-site
15 results
Show changes
Commits on Source (5)
...@@ -14,7 +14,10 @@ if (isset($_GET['key'])) { ...@@ -14,7 +14,10 @@ if (isset($_GET['key'])) {
} }
break; break;
case "postcode": case "postcode":
echo lookup_postcode($_GET['value']); $postcode = validPostcode($_GET['value']);
if ($postcode != false) {
lookup_postcode($postcode);
}
break; break;
case "username": case "username":
$username = $_GET['value']; $username = $_GET['value'];
......
var validation = {"studentid":false, "username":false, "realname":false, "address":false, "contact":false, "email":false, "phone":false}; var validation = {
"studentid": false,
"username": false,
"realname": false,
"address": false,
"contact": false,
"email": false,
"phone": false
};
var submitted = false; var submitted = false;
function validate(){ function validate() {
var valid = true; var valid = true;
for (field in req){ for (field in req) {
if (!validation[req[field]]){ if (!validation[req[field]]) {
valid=false; valid = false;
break; break;
} }
} }
if((valid || ($('input#override:checked').size()==1)) && !submitted && ($('input#tnc:checked').size()==1)){ if ((valid || ($('input#override:checked').size() == 1)) && !submitted && ($('input#tnc:checked').size() == 1)) {
$('input#submit').removeAttr("disabled"); $('input#submit').removeAttr("disabled");
return true; return true;
} }
else{ else {
$('input#submit').attr("disabled","disabled"); $('input#submit').attr("disabled", "disabled");
return false; return false;
} }
} }
function processPostcode(){ function processPostcode() {
// lookup postcode // lookup postcode
$.getJSON("signup/ajax",{key: "postcode",value: $('input#postcode').val()}, function(j){ $.getJSON("signup/ajax", {key: "postcode", value: $('input#postcode').val()}, function (j) {
//populate dropdown //populate dropdown
var options = ''; var options = '';
if (j.addresses.length > 1) { if (j.addresses.length > 1) {
// make dropdown visible // make dropdown visible
$('div#addseldiv').removeAttr("style"); $('div#addseldiv').removeAttr("style");
for (var i = 0; i < (j.addresses.length); i++) { for (var i = 0; i < (j.addresses.length); i++) {
options += '<option>'; options += '<option>';
if (j.addresses[i].flat != null) { if (j.addresses[i].flat != null) {
options += j.addresses[i].flat + "\n"; options += j.addresses[i].flat + "\n";
} }
if (j.addresses[i].house != null) { if (j.addresses[i].house != null) {
options += j.addresses[i].house + "\n"; options += j.addresses[i].house + "\n";
} }
if (j.addresses[i].road != null) { if (j.addresses[i].road != null) {
options += j.addresses[i].road + "\n"; options += j.addresses[i].road + "\n";
} }
if (j.addresses[i].city != null) { if (j.addresses[i].city != null) {
options += j.addresses[i].city + "\n"; options += j.addresses[i].city + "\n";
} }
options += '</option>'; options += '</option>';
} }
$("select#addsel").html(options); $("select#addsel").html(options);
$('select#addsel option:first').attr('selected', 'selected'); $('select#addsel option:first').attr('selected', 'selected');
} }
if (j.addresses.length == 1) { if (j.addresses.length == 1) {
$('div#addseldiv').attr("style","display:none"); $('div#addseldiv').attr("style", "display:none");
$("textarea#address") $("textarea#address")
$('div#addressmessage').attr("style","color:green; float:right; clear:right;"); $('div#addressmessage').attr("style", "color:green; float:right; clear:right;");
$('div#addressmessage').html("OK"); $('div#addressmessage').html("OK");
validation["address"]=true; validation["address"] = true;
validate(); validate();
} }
}) })
} }
function lookupSID(setname){ function lookupSID(setname) {
$.get("/signup/ajax",{key:"sid" ,value: $('input#studentid').val()},function(j){ $.get("/signup/ajax", {key: "sid", value: $('input#studentid').val()}, function (j) {
arr=j.split(":"); arr = j.split(":");
key=arr.shift(); key = arr.shift();
val=arr.join(":"); val = arr.join(":");
if(key=="OK"){ if (key == "OK") {
if(setname=true) if (setname = true)
$("input#realname").val(val); $("input#realname").val(val);
$('div#studentidmessage').attr("style","color:green; float:right; clear:right;"); $('div#studentidmessage').attr("style", "color:green; float:right; clear:right;");
$('div#studentidmessage').html(key); $('div#studentidmessage').html(key);
validation['studentid']=true; validation['studentid'] = true;
processName("realname","realname"); processName("realname", "realname");
} }
else{ else {
$('div#studentidmessage').attr("style","color:red; float:right; clear:right;"); $('div#studentidmessage').attr("style", "color:red; float:right; clear:right;");
$('div#studentidmessage').html(val); $('div#studentidmessage').html(val);
validation['email']=false; validation['email'] = false;
validate(); validate();
} }
},'text') }, 'text')
} }
function processSID(){ function processSID() {
lookupSID(true); lookupSID(true);
} }
function processUsername(){ function processUsername() {
$.get("/signup/ajax",{key: "username", value: $('input#username').val()},function(j){ $.get("/signup/ajax", {key: "username", value: $('input#username').val()}, function (j) {
if (j!="OK") { if (j != "OK") {
$('div#usernamemessage').attr("style","color:red; float:right; clear:right;"); $('div#usernamemessage').attr("style", "color:red; float:right; clear:right;");
validation['username']=false; validation['username'] = false;
} }
else{ else {
$('div#usernamemessage').attr("style","color:green; float:right; clear:right;"); $('div#usernamemessage').attr("style", "color:green; float:right; clear:right;");
validation['username']=true; validation['username'] = true;
} }
$('div#usernamemessage').html(j); $('div#usernamemessage').html(j);
validate(); validate();
},'text') }, 'text')
} }
function processName(type, input){ function processName(type, input) {
$.get("/signup/ajax",{key: type, value: $('input#'+input).val()},function(j){ $.get("/signup/ajax", {key: type, value: $('input#' + input).val()}, function (j) {
if (j!="OK") { if (j != "OK") {
$('div#'+input+'message').attr("style","color:red; float:right; clear:right;"); $('div#' + input + 'message').attr("style", "color:red; float:right; clear:right;");
validation[input]=false; validation[input] = false;
} }
else{ else {
$('div#'+input+'message').attr("style","color:green; float:right; clear:right;"); $('div#' + input + 'message').attr("style", "color:green; float:right; clear:right;");
validation[input]=true; validation[input] = true;
} }
$('div#'+input+'message').html(j); $('div#' + input + 'message').html(j);
validate(); validate();
},'text') }, 'text')
} }
function processContact(){ function processContact() {
processName('realname','contact'); processName('realname', 'contact');
} }
function processAddress(){ function processAddress() {
$.get("/signup/ajax",{key: "address", value: $('textarea#address').val()},function(j){ $.get("/signup/ajax", {key: "address", value: $('textarea#address').val()}, function (j) {
if (j!="OK") { if (j != "OK") {
$('div#addressmessage').attr("style","color:red; float:right; clear:right;"); $('div#addressmessage').attr("style", "color:red; float:right; clear:right;");
validation['address']=false; validation['address'] = false;
} }
else{ else {
$('div#addressmessage').attr("style","color:green; float:right; clear:right;"); $('div#addressmessage').attr("style", "color:green; float:right; clear:right;");
validation['address']=true; validation['address'] = true;
} }
$('div#addressmessage').html(j); $('div#addressmessage').html(j);
validate(); validate();
},'text') }, 'text')
} }
function processEmail(){ function processEmail() {
$.get("/signup/ajax",{key: "email", value: $('input#email').val()},function(j){ $.get("/signup/ajax", {key: "email", value: $('input#email').val()}, function (j) {
if (j!="OK") { if (j != "OK") {
$('div#emailmessage').attr("style","color:red; float:right; clear:right;"); $('div#emailmessage').attr("style", "color:red; float:right; clear:right;");
validation['email']=false; validation['email'] = false;
} }
else{ else {
$('div#emailmessage').attr("style","color:green; float:right; clear:right;"); $('div#emailmessage').attr("style", "color:green; float:right; clear:right;");
validation['email']=true; validation['email'] = true;
} }
$('div#emailmessage').html(j); $('div#emailmessage').html(j);
validate(); validate();
},'text') }, 'text')
} }
function processPhone(){ function processPhone() {
$.get("/signup/ajax",{key: "phone", value: $('input#phone').val()},function(j){ $.get("/signup/ajax", {key: "phone", value: $('input#phone').val()}, function (j) {
if (j!="OK") { if (j != "OK") {
$('div#phonemessage').attr("style","color:red; float:right; clear:right;"); $('div#phonemessage').attr("style", "color:red; float:right; clear:right;");
validation['phone']=false; validation['phone'] = false;
} }
else{ else {
$('div#phonemessage').attr("style","color:green; float:right; clear:right;"); $('div#phonemessage').attr("style", "color:green; float:right; clear:right;");
validation['phone']=true; validation['phone'] = true;
} }
$('div#phonemessage').html(j); $('div#phonemessage').html(j);
validate(); validate();
},'text') }, 'text')
} }
$(function(){ $(function () {
if($('input#studentid').size()==1){ if ($('input#studentid').size() == 1) {
usertype=1; usertype = 1;
} }
else if($('input#contact').size()==1){ else if ($('input#contact').size() == 1) {
usertype=2; usertype = 2;
} }
else{ else {
usertype=5; usertype = 5;
} }
req=new Array("username","realname","email","phone"); req = new Array("username", "realname", "email", "phone");
switch(usertype){ switch (usertype) {
case "1": case "1":
req.push("studentid","address"); req.push("studentid", "address");
break; break;
case "2": case "2":
req.push("contact"); req.push("contact");
break; break;
case "5": case "5":
req.push("address"); req.push("address");
}
//usertype=$('input#usertype').val();
$("document").ready(function () {
// makes script sutff appear
$('div#postcodediv').removeAttr("style");
$('input#submit').attr("disabled", "disabled");
// if the fields are not empty validate them
if ($('input#username').val() != "") processUsername();
if ($('input#email').val() != "") processEmail();
if ($('input#phone').val() != "") processPhone();
if (usertype != 2) {
if ($('input#postcode').val() != "") processPostcode();
if ($('textarea#address').val() != "") processAddress();
if ($('input#realname').val() != "") processName("realname", "realname");
}
else {
if ($('input#contact').val() != "") processContact();
if ($('input#realname').val() != "") processName("socname", "realname");
} }
//usertype=$('input#usertype').val(); if ((usertype == 1) && ($('input#studentid').val() != "")) {
$("document").ready(function(){ if ($('input#realname').val() == "") lookupSID(true);
// makes script sutff appear else lookupSID(false);
$('div#postcodediv').removeAttr("style"); }
$('input#submit').attr("disabled","disabled");
// if the fields are not empty validate them validate();
if($('input#username').val()!="") processUsername(); })
if($('input#email').val()!="") processEmail(); // dont do address stuff for societies
if($('input#phone').val()!="") processPhone(); if (usertype != 2) {
if(usertype!=2){ // process postcode when the box changes
if($('input#postcode').val()!="") processPostcode(); $("input#postcode").change(processPostcode);
if($('textarea#address').val()!="") processAddress();
if($('input#realname').val()!="") processName("realname","realname");
}
else{
if($('input#contact').val()!="") processContact();
if($('input#realname').val()!="") processName("socname","realname");
}
if((usertype==1) && ($('input#studentid').val()!="")){
if($('input#realname').val()=="") lookupSID(true);
else lookupSID(false);
}
validate(); //populate the address box when an address is selected
}) $("select#addsel").change(function () {
// dont do address stuff for societies
if(usertype!=2){ // everything is shit and will strip out the line breaks
// process postcode when the box changes // so we have to do weird shit with innerHTML
$("input#postcode").change(processPostcode);
// store the entire options as e
//populate the address box when an address is selected var e = document.getElementById("addsel");
$("select#addsel").change(function(){ // store the selected address's innerHTML as strUser (because stackpver flow copy and paste)
var strUser = e.options[e.selectedIndex].innerHTML;
// everything is shit and will strip out the line breaks // set the text area to the strUser var
// so we have to do weird shit with innerHTML $("textarea#address").text(strUser);
$('div#addressmessage').attr("style", "color:green; float:right; clear:right;");
// store the entire options as e $('div#addressmessage').html("OK");
var e = document.getElementById("addsel"); validation['address'] = true;
// store the selected address's innerHTML as strUser (because stackpver flow copy and paste) })
var strUser = e.options[e.selectedIndex].innerHTML; }
// set the text area to the strUser var //else deal with the contact field
$("textarea#address").text( strUser ); else {
$('div#addressmessage').attr("style","color:green; float:right; clear:right;");
$('div#addressmessage').html("OK");
validation['address']=true;
})
}
//else deal with the contact field
else{
$("input#contact").change(processContact) $("input#contact").change(processContact)
} }
//if is a student //if is a student
if(usertype==1){ if (usertype == 1) {
//lookup the real name from the studentid //lookup the real name from the studentid
$("input#studentid").change(processSID) $("input#studentid").change(processSID)
} }
//validate username //validate username
$("input#username").change(processUsername) $("input#username").change(processUsername)
//validate personal and society names differntly //validate personal and society names differntly
if(usertype!=2){ if (usertype != 2) {
persoc='realname'; persoc = 'realname';
} }
else{ else {
persoc='socname'; persoc = 'socname';
} }
//validate real name //validate real name
$("input#realname").change(function(){ $("input#realname").change(function () {
processName(persoc, 'realname'); processName(persoc, 'realname');
}) })
//validate email address //validate email address
$("input#email").change(processEmail); $("input#email").change(processEmail);
//validate phone number //validate phone number
$("input#phone").change(processPhone); $("input#phone").change(processPhone);
$("textarea#address").change(processAddress); $("textarea#address").change(processAddress);
$("input#override").change(validate); $("input#override").change(validate);
$("input#tnc").change(validate); $("input#tnc").change(validate);
// Disable the submit button once clicked // Disable the submit button once clicked
$("form#mainform").submit(function() { $("form#mainform").submit(function () {
var valid = validate(); var valid = validate();
if(valid){ if (valid) {
// mark form as submitted // mark form as submitted
submitted = true; submitted = true;
// disable the submit button // disable the submit button
$('input#submit').attr("disabled","disabled"); $('input#submit').attr("disabled", "disabled");
} }
return valid; return valid;
}); });
}) })
...@@ -9,4 +9,12 @@ function sanitizeAddress($address) ...@@ -9,4 +9,12 @@ function sanitizeAddress($address)
return str_replace(array("\r\n", "\r"), array("\n", "\n"), $address); return str_replace(array("\r\n", "\r"), array("\n", "\n"), $address);
} }
function sanitizePostcode($postcode)
{
//force uppercase, remove any possible stupid spaces and add the single space in the correct place
$postcode = strtoupper($postcode);
$postcode = str_replace(" ", "", $postcode);
return substr_replace($postcode, " ", -3, 0);
}
?> ?>
...@@ -252,11 +252,22 @@ function validAddress($address) ...@@ -252,11 +252,22 @@ function validAddress($address)
} }
} }
function validPostcode($postcode)
{
$postcode = sanitizePostcode($postcode);
if (!preg_match('/^[A-Z]{1,2}[0-9]{1,2}[A-Z]{0,1} [0-9][A-Z]{2}$/', $postcode)) {
return false;
} else {
return $postcode;
}
}
function validPhone($phone) function validPhone($phone)
{ {
global $error; global $error;
$phone = sanitizePhone($phone); $phone = sanitizePhone($phone);
if (!preg_match("/^\+?[0-9-]+$/", $phone)) { if (!preg_match("/^\+?[0-9-]{10,}$/", $phone)) {
$error = "Must be all numbers"; $error = "Must be all numbers";
return false; return false;
} }
...@@ -266,7 +277,7 @@ function validPhone($phone) ...@@ -266,7 +277,7 @@ function validPhone($phone)
function validSignupEmail($email) function validSignupEmail($email)
{ {
global $error; global $error;
if (preg_match('/@sucs\.org$/', $email)) { if (preg_match('/@sucs\.$/', $email)) {
$error = "SUCS email addresses are not allowed"; $error = "SUCS email addresses are not allowed";
return false; return false;
} elseif (!validEmail($email)) { } elseif (!validEmail($email)) {
......
<? <?
// lookup real names from sid's useing campus ldap // lookup real names from sid's using campus ldap
function lookupSID($sid) function lookupSID($sid)
{ {
$ds = ldap_connect("ccs-suld1.swan.ac.uk"); $ds = ldap_connect("ccs-suld1.swan.ac.uk");
...@@ -12,7 +12,7 @@ function lookupSID($sid) ...@@ -12,7 +12,7 @@ function lookupSID($sid)
return ucwords(strtolower($info[0]['givenname'][0] . " " . $info[0]['sn'][0])); return ucwords(strtolower($info[0]['givenname'][0] . " " . $info[0]['sn'][0]));
} }
// lookup addresses from postcodes useing the univeritys website // lookup addresses from postcodes using the university's website
function lookup_postcode($postcode) function lookup_postcode($postcode)
{ {
...@@ -21,9 +21,8 @@ function lookup_postcode($postcode) ...@@ -21,9 +21,8 @@ function lookup_postcode($postcode)
$url = "http://paf.sucs.org/?apikey=$apikey&postcode=" . rawurlencode($postcode); $url = "http://paf.sucs.org/?apikey=$apikey&postcode=" . rawurlencode($postcode);
$req = curl_init($url); $req = curl_init($url);
$page = curl_exec($req); curl_exec($req);
curl_close($req); curl_close($req);
} }
?> ?>