science-ation/user_edit.inc.php

168 lines
4.6 KiB
PHP

<?
/*
This file is part of the 'Science Fair In A Box' project
SFIAB Website: http://www.sfiab.ca
Copyright (C) 2010 David Grant <dave@lightbox.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation, version 2.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
?>
<?
require_once('account.inc.php');
function user_edit_item(&$u, $label, $fname, $type='textbox', $data1=NULL, $data2=NULL)
{
global $required, $fields, $config;
if(!in_array($fname, $fields)) {
echo '<td></td><td></td>';
return;
}
$req = in_array($fname, $required) ? REQUIREDFIELD : '';
$c = ($label == '') ? '' : ':';
echo "<td><label for=\"$fname\">$req".i18n($label)."$c</label></td>";
echo '<td>';
switch($type) {
case 'textbox':
if($data1 != NULL) $size = "size=\"$data1\"";
echo "<input id=\"$fname\" name=\"$fname\" $size type=\"text\" value=\"{$u[$fname]}\">";
break;
case 'province':
emit_province_selector($fname, $u[$fname]);
break;
case 'yesno':
echo "<select name=\"$fname\">";
$sel = ($u[$fname]=='yes') ? 'selected="selected"' : '';
echo "<option value=\"yes\" $sel>".i18n("Yes")."</option>\n";
$sel = ($u[$fname]=='no') ? 'selected="selected"' : '';
echo "<option value=\"no\" $sel>".i18n("No")."</option>\n";
echo "</select>";
break;
case 'sex':
echo "<select name=\"$fname\">";
echo "<option value=\"\">".i18n("Choose")."</option>\n";
if($u['sex']=="male") $sel="selected=\"selected\""; else $sel="";
echo "<option value=\"male\" $sel>".i18n("Male")."</option>\n";
if($u['sex']=="female") $sel="selected=\"selected\""; else $sel="";
echo "<option value=\"female\" $sel>".i18n("Female")."</option>\n";
break;
case 'language':
echo "<select name=\"$fname\">";
echo "<option value=\"\">".i18n("Choose")."</option>\n";
foreach($config['languages'] AS $l=>$ln) {
if($u['lang']==$l) $sel="selected=\"selected\""; else $sel="";
echo "<option value=\"$l\" $sel>".i18n($ln)."</option>\n";
}
echo "</select>";
break;
case 'languages':
echo "<span>";
$x = 0;
foreach($config['languages'] AS $l=>$ln) {
$ch = (in_array($l,$u['languages'])) ? 'checked="checked"' : '';
if($x) echo '<br />';
echo "<label><input $ch type=\"checkbox\" name=\"$fname\" value=\"$l\" /> $ln</label>";
$x=1;
}
echo "</span>";
break;
case 'checklist':
/* data1 = items, data2 = checked items */
echo "<span>";
$x = 0;
foreach($data1 AS $key=>$txt) {
$ch = (in_array($key,$data2)) ? 'checked="checked"' : '';
if($x) echo '<br />';
echo "<label><input $ch type=\"checkbox\" name=\"$fname\" value=\"$key\" /> $txt</label>";
$x=1;
}
echo "</span>";
break;
}
echo '</td>';
}
function user_account_status(&$u, $a = null)
{
if(is_array($u)) {
$a = account_load($u['accounts_id']);
}
if($a['username'] == '')
return 'incomplete';
return 'complete';
}
function user_personal_info_status(&$u)
{
$required = array();
foreach(array_keys($u['roles']) as $r) {
$required = array_merge($required, user_fields_required($r));
}
$our_fields = array('salutation', 'firstname','lastname','address',
'address2','city','province','postalcode',
'phonehome','phonecell','language','sex',
'firstaid','cpr','birthdate','grade');
$required = array_intersect($our_fields, $required);
foreach($required as $r) {
if($r=="birthdate") {
if($u[$r]=="0000-00-00" || !$u[$r])
return "incomplete";
}
if(trim($u[$r]) == '') return 'incomplete';
}
/* FIXME: somehow call the $role _status_update() function to update
* the individual [$role]['complete'] entry? */
return 'complete';
}
function user_organization_status(&$u)
{
$required = array();
foreach(array_keys($u['roles']) as $r) {
$required = array_merge($required, user_fields_required($r));
}
$our_fields = array('organization', 'phonework','fax');
$required = array_intersect($our_fields, $required);
foreach($required as $r) {
if(trim($u[$r]) == '') return 'incomplete';
}
/* FIXME: somehow call the $role _status_update() function to update
* the individual [$role]['complete'] entry? */
return 'complete';
}
function user_roles_status(&$u)
{
return 'complete';
}
?>