RP,
Here is the page I use to display a form of checkboxes. (case 800)
It also processes the input from the form. (case 810)
Many functions or subroutines are not include; but the essential
routine (maArrayExpand) is included.
Robert
............
<?
require ("com.php3");
require ("common.php3");
require ("common-app.php3");
maStart($seId);
$kv= maArrayRead();
$akvPeSt= unserialize($kv['kvPeSt']);
$akvTe= unserialize($kv['kvTe']);
if ($akvTe['kvTeKv'] == 'y') maEchoArray($kv, 'admin');
if ($akvTe['kvTeVa'] == 'y') maEchoVARS('admin');
function maAdminInstr()
{ maEchoGreen('To add or delete privileges toggle the "checkmarks".</B>');
}
function maAdminForm() {
global $maQuery,$erErNo,$erEr,$maQsNa, $seAr, $coGreen, $sqLi,$sqNo,$sqSc;
$sqNo = 10; // display 10 at a time
$maQuery= "SELECT * FROM user LIMIT $sqLi, $sqNo";
$result = @($maQuery);
if (maSqErTest())
return;
$numRows = mysql_num_rows($result);
if ($numRows == 0)
{ $erErNo= mysql_error(); $erEr= 'Error 193 '.mysql_error(); maSqErRecord('q');
die("Sorry. Please try later. Error 193 will be fixed.");
}
else
{ printf('%s%sViewing %d to %d of %d users.</FONT>',
"\n",
$coGreen,
$sqLi+1,
($sqLi+$sqNo<$sqSc)?$sqLi+$sqNo:$sqSc,
$sqSc );
// DISPLAY ROWS FROM DATA BASE, ALTERNATE COLOURS ON EACH ROW
$xqs= "&maCo=810&sqLi=$sqLi&sqNo=$sqNo&sqSc=$sqSc"?>
<form action="admin<?echo $maQsNa.$xqs?>" method="post">
<input type="hidden" name="fseFoSe" value="<?echo $seAr['seFoSe']?>">
<table border="1">
<?
$ixEnd= $sqSc - $sqLi; // how many are left to see
$ixEnd= min($ixEnd, $sqNo); // how many OR maximun
for ($ix=0; $ix < $ixEnd; $ix++) // loop thru them
{ $rUser= mysql_fetch_array($result); // get a user
$xusId= $rUser['usId'];
$xkv= maArrayRead($xusId); // read kv table for this user
$xakvPeSt= unserialize($xkv['kvPeSt']); // get PErmissions for STolen
$xColour= ($ix%2) ?"#ffffdd":"#dddddd";
?>
<tr bgcolor="<?echo $xColour?>">
<td><?echo htmlspecialchars($rUser['usPs'])?>
<input type="hidden" name="fusId[]" value="<?echo $xusId?>">
<td><input type="checkbox" name="fchSu[<?echo $ix?>]" value="<?echo $ix?>" <?echo ($xakvPeSt['kvPeStSubmit']=='y')?'checked':''?>>Submit
<td><input type="checkbox" name="fchCh[<?echo $ix?>]" value="<?echo $ix?>" <?echo ($xakvPeSt['kvPeStChange']=='y')?'checked':''?>>Change
<td><input type="checkbox" name="fchDe[<?echo $ix?>]" value="<?echo $ix?>" <?echo ($xakvPeSt['kvPeStDelete']=='y')?"checked":""?>>Delete
<td><input type="checkbox" name="fchAd[<?echo $ix?>]" value="<?echo $ix?>" <?echo ($xakvPeSt['kvPeStAdmin'] =='y')?"checked":""?>>Admin
</tr>
<?
}
?>
</table>
<br /><input type="submit" value="Save these and show more.">
</form>
<?
} // end printf...Viewing...
} // end maAdminForm
function maArrayExpand($aIn, $count)
{ // output array is input array spread over 'count' entries; brouser percolates values to top.
for ( $ix=0 ; $ix<$count ; $ix++ )
$aOut[$ix]= -1; // init array to -1
$count= count($aIn);
for ( $ix=0 ; $ix<$count ; $ix++ ) // loop thru actual input data
$aOut[$aIn[$ix]]= $aIn[$ix]; // put input values in 'input value' slot
return($aOut);
}
function maAdminSave()
{ global $maQuery,$erErNo,$erEr, $fchSu, $fchCh, $fchDe, $fchAd, $fusId;
// SPREAD ARRAYS INTO PROPER ARRAY SLOTS, USE ARRAY VALUES
$ixRows= count($fusId);
$fchSu= maArrayExpand($fchSu, $ixRows);
$fchCh= maArrayExpand($fchCh, $ixRows);
$fchDe= maArrayExpand($fchDe, $ixRows);
$fchAd= maArrayExpand($fchAd, $ixRows);
// LOOP THRU ARRAYS OF CHECKBOXES, UPDATE USERS
for ($ix=0 ; $ix<$ixRows ; $ix++)
{ $xkv= maArrayRead($fusId[$ix]); // get a user
// echo 'kvPeST'.$xkv['kvPeSt'];
$xakvPeSt= unserialize($xkv['kvPeSt']);
$xakvPeSt['kvPeStSubmit']= ($fchSu[$ix]==$ix) ? 'y':'n';
$xakvPeSt['kvPeStChange']= ($fchCh[$ix]==$ix) ? 'y':'n';
$xakvPeSt['kvPeStDelete']= ($fchDe[$ix]==$ix) ? 'y':'n';
$xakvPeSt['kvPeStAdmin'] = ($fchAd[$ix]==$ix) ? 'y':'n';
$ser= serialize($xakvPeSt);
$kvNew= array('kvPeSt' => $ser);
$xkv= maArrayWrite($kvNew, $xkv, $fusId[$ix]); // write that user
} // end for
} // end maSaveChange
// MAIN LINE
switch($maCo) {
case 800: // first time, put up instructions
// only show search instructions first few times
$usAdCo= $kv['usAdCo'];
if ($usAdCo < 5)
{ $usAdCo++;
$kvNew= array('usAdCo'=> $usAdCo );
$kv= maArrayWrite($kvNew, $kv); // save new ADmin COunt
unset($kvNew);
maAdminInstr();
}
$sqLi= 0;
$sqSc = maCount('user');
maAdminForm(); // display some users and permissions (sqNo)
break; // end 800
case 810:
if ( ! (isset($fseFoSe) && $fseFoSe==$seAr['seFoSe'])) // if form sequence missing or wrong
maDuplicateForm(197);
else
maAdminSave(); // save prior users' permissions
seFoSe_bump();
$sqLi+= $sqNo;
if ($sqLi >= $sqSc)
$sqLi= 0;
maAdminForm(); // display some users and permissions (sqNo)
break; // end 810
default: // error
$erErNo= 190; $erEr= "maCo:$maCo out of range."; maSqErRecord('q');
return;
} // end switch(maCo)
?>
</body>