Show access code in schools list

Add ability to create access codes for all schools and to remove access codes from all schools
Update generatePassword to accept a password length as a parameter, defaults to 8
This commit is contained in:
james 2006-12-06 19:24:09 +00:00
parent 8fd2a44050
commit 1e7d9fcad9
2 changed files with 26 additions and 2 deletions

View File

@ -80,6 +80,24 @@
echo happy("School successfully deleted");
}
if($_GET['action']=="clearaccesscodes")
{
mysql_query("UPDATE schools SET accesscode=NULL WHERE year='{$config['FAIRYEAR']}'");
echo happy("Access Codes successfully cleared from all schools");
}
if($_GET['action']=="makeaccesscodes")
{
$q=mysql_query("SELECT id FROM schools WHERE year='{$config['FAIRYEAR']}' AND (accesscode IS NULL OR accesscode='')");
while($r=mysql_fetch_object($q))
{
$ac=generatePassword(5);
mysql_query("UPDATE schools SET accesscode='$ac' WHERE id='$r->id' AND year='{$config['FAIRYEAR']}'");
}
echo happy("Access Codes successfully set for schools that didn't have one");
}
if($_GET['action']=="edit" || $_GET['action']=="add")
{
@ -182,6 +200,10 @@
echo "<br />";
echo "<a href=\"schoolsimport.php?action=add\">Import Schools from CSV</a>\n";
echo "<br />";
echo "<a href=\"schools.php?action=makeaccesscodes\">Create Access Code for any school without one</a>\n";
echo "<br />";
echo "<a onclick=\"return confirmClick('".i18n("Are you sure you want to remove all access codes from all schools?")."')\" href=\"schools.php?action=clearaccesscodes\">Remove Access Codes from all schools</a>\n";
echo "<br />";
echo "<table class=\"summarytable\">";
echo "<tr>";
echo " <th>School</th>";
@ -190,6 +212,7 @@
echo " <th>Contact</th>";
if($config['participant_registration_type']=="schoolpassword")
echo " <th>Reg Pass</th>";
echo " <th>Access Code</th>";
echo " <th>Action</th>";
echo "</tr>\n";
@ -203,6 +226,7 @@
echo " <td>$r->sciencehead</td>\n";
if($config['participant_registration_type']=="schoolpassword")
echo " <td>$r->registration_password</td>\n";
echo " <td>$r->accesscode</td>\n";
echo " <td align=\"center\">";
echo "<a href=\"schools.php?action=edit&edit=$r->id\"><img border=\"0\" src=\"".$config['SFIABDIRECTORY']."/images/16/edit.".$config['icon_extension']."\"></a>";

View File

@ -836,14 +836,14 @@ function output_page_text($textname)
echo i18n($r->text);
}
function generatePassword()
function generatePassword($pwlen=8)
{
//these are good characters that are not easily confused with other characters :)
$available="ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz23456789";
$len=strlen($available);
$key="";
for($x=0;$x<8;$x++)
for($x=0;$x<$pwlen;$x++)
{
$key.=$available[rand(0,$len)];
}