made the profile system more exstensible by adding an "editable" field to profile fields, and adding "visible" and "editible" fields to the profile category
This commit is contained in:
parent
29406354f3
commit
0edcfad5f5
3 changed files with 117 additions and 71 deletions
|
|
@ -288,55 +288,54 @@ sub www_editProfile {
|
|||
$f->hidden("uid",$session{user}{userId});
|
||||
$a = WebGUI::SQL->read("select * from userProfileField,userProfileCategory
|
||||
where userProfileField.profileCategoryId=userProfileCategory.profileCategoryId
|
||||
and userProfileCategory.editable=1 and userProfileField.editable=1
|
||||
order by userProfileCategory.sequenceNumber,userProfileField.sequenceNumber");
|
||||
while(%data = $a->hash) {
|
||||
if ($data{visible}) {
|
||||
$category = eval $data{categoryName};
|
||||
if ($category ne $previousCategory) {
|
||||
$f->raw('<tr><td colspan="2" class="tableHeader">'.$category.'</td></tr>');
|
||||
}
|
||||
$values = eval $data{dataValues};
|
||||
$method = $data{dataType};
|
||||
$label = eval $data{fieldLabel};
|
||||
if ($data{required}) {
|
||||
$subtext = "*";
|
||||
} else {
|
||||
$subtext = "";
|
||||
}
|
||||
if ($method eq "select") {
|
||||
# note: this big if statement doesn't look elegant, but doing regular
|
||||
# ORs caused problems with the array reference.
|
||||
if ($session{form}{$data{fieldName}}) {
|
||||
$default = [$session{form}{$data{fieldName}}];
|
||||
} elsif ($session{user}{$data{fieldName}}) {
|
||||
$default = [$session{user}{$data{fieldName}}];
|
||||
} else {
|
||||
$default = eval $data{dataDefault};
|
||||
}
|
||||
$f->select(
|
||||
-name=>$data{fieldName},
|
||||
-options=>$values,
|
||||
-label=>$label,
|
||||
-value=>$default,
|
||||
-subtext=>$subtext
|
||||
);
|
||||
} else {
|
||||
if ($session{form}{$data{fieldName}}) {
|
||||
$default = $session{form}{$data{fieldName}};
|
||||
} elsif (exists $session{user}{$data{fieldName}}) {
|
||||
$default = $session{user}{$data{fieldName}};
|
||||
} else {
|
||||
$default = eval $data{dataDefault};
|
||||
}
|
||||
$f->$method(
|
||||
-name=>$data{fieldName},
|
||||
-label=>$label,
|
||||
-value=>$default,
|
||||
-subtext=>$subtext
|
||||
);
|
||||
}
|
||||
$previousCategory = $category;
|
||||
$category = eval $data{categoryName};
|
||||
if ($category ne $previousCategory) {
|
||||
$f->raw('<tr><td colspan="2" class="tableHeader">'.$category.'</td></tr>');
|
||||
}
|
||||
$values = eval $data{dataValues};
|
||||
$method = $data{dataType};
|
||||
$label = eval $data{fieldLabel};
|
||||
if ($data{required}) {
|
||||
$subtext = "*";
|
||||
} else {
|
||||
$subtext = "";
|
||||
}
|
||||
if ($method eq "select") {
|
||||
# note: this big if statement doesn't look elegant, but doing regular
|
||||
# ORs caused problems with the array reference.
|
||||
if ($session{form}{$data{fieldName}}) {
|
||||
$default = [$session{form}{$data{fieldName}}];
|
||||
} elsif ($session{user}{$data{fieldName}}) {
|
||||
$default = [$session{user}{$data{fieldName}}];
|
||||
} else {
|
||||
$default = eval $data{dataDefault};
|
||||
}
|
||||
$f->select(
|
||||
-name=>$data{fieldName},
|
||||
-options=>$values,
|
||||
-label=>$label,
|
||||
-value=>$default,
|
||||
-subtext=>$subtext
|
||||
);
|
||||
} else {
|
||||
if ($session{form}{$data{fieldName}}) {
|
||||
$default = $session{form}{$data{fieldName}};
|
||||
} elsif (exists $session{user}{$data{fieldName}}) {
|
||||
$default = $session{user}{$data{fieldName}};
|
||||
} else {
|
||||
$default = eval $data{dataDefault};
|
||||
}
|
||||
$f->$method(
|
||||
-name=>$data{fieldName},
|
||||
-label=>$label,
|
||||
-value=>$default,
|
||||
-subtext=>$subtext
|
||||
);
|
||||
}
|
||||
$previousCategory = $category;
|
||||
}
|
||||
$a->finish;
|
||||
$f->submit;
|
||||
|
|
@ -569,8 +568,7 @@ sub www_viewProfile {
|
|||
$output .= '<table>';
|
||||
$a = WebGUI::SQL->read("select * from userProfileField,userProfileCategory
|
||||
where userProfileField.profileCategoryId=userProfileCategory.profileCategoryId
|
||||
and userProfileCategory.profileCategoryId<>4
|
||||
and userProfileField.visible=1
|
||||
and userProfileCategory.visible=1 and userProfileField.visible=1
|
||||
order by userProfileCategory.sequenceNumber,userProfileField.sequenceNumber");
|
||||
while (%data = $a->hash) {
|
||||
$category = eval $data{categoryName};
|
||||
|
|
|
|||
|
|
@ -51,15 +51,15 @@ sub _reorderFields {
|
|||
sub _submenu {
|
||||
my (%menu);
|
||||
tie %menu, 'Tie::IxHash';
|
||||
$menu{WebGUI::URL::page("op=editProfileCategory")} = WebGUI::International::get(490);
|
||||
$menu{WebGUI::URL::page("op=editProfileField")} = WebGUI::International::get(491);
|
||||
$menu{WebGUI::URL::page("op=editProfileCategory")} = WebGUI::International::get(490,"WebGUI/Profile");
|
||||
$menu{WebGUI::URL::page("op=editProfileField")} = WebGUI::International::get(491,"WebGUI/Profile");
|
||||
if (($session{form}{op} eq "editProfileField" && $session{form}{fid} ne "new") || $session{form}{op} eq "deleteProfileField") {
|
||||
$menu{WebGUI::URL::page('op=editProfileField&fid='.$session{form}{fid})} = WebGUI::International::get(787);
|
||||
$menu{WebGUI::URL::page('op=deleteProfileField&fid='.$session{form}{fid})} = WebGUI::International::get(788);
|
||||
$menu{WebGUI::URL::page('op=editProfileField&fid='.$session{form}{fid})} = WebGUI::International::get(787,"WebGUI/Profile");
|
||||
$menu{WebGUI::URL::page('op=deleteProfileField&fid='.$session{form}{fid})} = WebGUI::International::get(788,"WebGUI/Profile");
|
||||
}
|
||||
if (($session{form}{op} eq "editProfileCategory" && $session{form}{cid} ne "new") || $session{form}{op} eq "deleteProfileCategory") {
|
||||
$menu{WebGUI::URL::page('op=editProfileCategory&cid='.$session{form}{cid})} = WebGUI::International::get(789);
|
||||
$menu{WebGUI::URL::page('op=deleteProfileCategory&cid='.$session{form}{cid})} = WebGUI::International::get(790);
|
||||
$menu{WebGUI::URL::page('op=editProfileCategory&cid='.$session{form}{cid})} = WebGUI::International::get(789,"WebGUI/Profile");
|
||||
$menu{WebGUI::URL::page('op=deleteProfileCategory&cid='.$session{form}{cid})} = WebGUI::International::get(790,"WebGUI/Profile");
|
||||
}
|
||||
$menu{WebGUI::URL::page("op=editProfileSettings")} = WebGUI::International::get(492);
|
||||
$menu{WebGUI::URL::page('op=manageSettings')} = WebGUI::International::get(4);
|
||||
|
|
@ -72,7 +72,7 @@ sub www_deleteProfileCategory {
|
|||
my ($output);
|
||||
return WebGUI::Privilege::vitalComponent() if ($session{form}{cid} < 1000);
|
||||
$output = '<h1>'.WebGUI::International::get(42).'</h1>';
|
||||
$output .= WebGUI::International::get(466).'<p>';
|
||||
$output .= WebGUI::International::get(466,"WebGUI/Profile").'<p>';
|
||||
$output .= '<div align="center"><a href="'.WebGUI::URL::page('op=deleteProfileCategoryConfirm&cid='.$session{form}{cid}).
|
||||
'">'.WebGUI::International::get(44).'</a>';
|
||||
$output .= ' <a href="'.WebGUI::URL::page('op=editProfileSettings').'">'.
|
||||
|
|
@ -96,7 +96,7 @@ sub www_deleteProfileField {
|
|||
($protected) = WebGUI::SQL->quickArray("select protected from userProfileField where fieldname=".quote($session{form}{fid}));
|
||||
return WebGUI::Privilege::vitalComponent() if ($protected);
|
||||
$output = '<h1>'.WebGUI::International::get(42).'</h1>';
|
||||
$output .= WebGUI::International::get(467).'<p>';
|
||||
$output .= WebGUI::International::get(467,"WebGUI/Profile").'<p>';
|
||||
$output .= '<div align="center"><a href="'.WebGUI::URL::page('op=deleteProfileFieldConfirm&fid='.$session{form}{fid}).
|
||||
'">'.WebGUI::International::get(44).'</a>';
|
||||
$output .= ' <a href="'.WebGUI::URL::page('op=editProfileSettings').'">'.
|
||||
|
|
@ -120,7 +120,7 @@ sub www_editProfileCategory {
|
|||
return WebGUI::Privilege::adminOnly() unless (WebGUI::Privilege::isInGroup(3));
|
||||
my ($output, $f, %data);
|
||||
tie %data, 'Tie::CPHash';
|
||||
$output = '<h1>'.WebGUI::International::get(468).'</h1>';
|
||||
$output = '<h1>'.WebGUI::International::get(468,"WebGUI/Profile").'</h1>';
|
||||
$f = WebGUI::HTMLForm->new;
|
||||
$f->hidden("op","editProfileCategorySave");
|
||||
if ($session{form}{cid}) {
|
||||
|
|
@ -131,6 +131,16 @@ sub www_editProfileCategory {
|
|||
$f->hidden("cid","new");
|
||||
}
|
||||
$f->text("categoryName",WebGUI::International::get(470),$data{categoryName});
|
||||
$f->yesNo(
|
||||
-name=>"visible",
|
||||
-label=>WebGUI::International::get(473,"WebGUI/Profile"),
|
||||
-value=>$data{visible}
|
||||
);
|
||||
$f->yesNo(
|
||||
-name=>"editable",
|
||||
-value=>$data{editable},
|
||||
-label=>WebGUI::International::get(897,"WebGUI/Profile")
|
||||
);
|
||||
$f->submit;
|
||||
$output .= $f->print;
|
||||
return _submenu($output);
|
||||
|
|
@ -139,19 +149,19 @@ sub www_editProfileCategory {
|
|||
#-------------------------------------------------------------------
|
||||
sub www_editProfileCategorySave {
|
||||
return WebGUI::Privilege::adminOnly() unless (WebGUI::Privilege::isInGroup(3));
|
||||
my ($categoryId, $sequenceNumber, $test);
|
||||
my ($sequenceNumber, $test);
|
||||
$session{form}{categoryName} = 'Unamed' if ($session{form}{categoryName} eq "" || $session{form}{categoryName} eq "''");
|
||||
$test = eval($session{form}{categoryName});
|
||||
$session{form}{categoryName} = "'".$session{form}{categoryName}."'" if ($test eq "");
|
||||
if ($session{form}{cid} eq "new") {
|
||||
$categoryId = getNextId("profileCategoryId");
|
||||
$session{form}{cid} = getNextId("profileCategoryId");
|
||||
($sequenceNumber) = WebGUI::SQL->quickArray("select max(sequenceNumber) from userProfileCategory");
|
||||
WebGUI::SQL->write("insert into userProfileCategory values ($categoryId, ".quote($session{form}{categoryName}).",
|
||||
".($sequenceNumber+1).")");
|
||||
} else {
|
||||
WebGUI::SQL->write("update userProfileCategory set categoryName=".quote($session{form}{categoryName})." where
|
||||
profileCategoryId=$session{form}{cid}");
|
||||
WebGUI::SQL->write("insert into userProfileCategory values ($session{form}{cid}, "
|
||||
.($sequenceNumber+1).")");
|
||||
}
|
||||
WebGUI::SQL->write("update userProfileCategory set categoryName=".quote($session{form}{categoryName}).",
|
||||
editable=".$session{form}{editable}.", visible=".$session{form}{visible}."
|
||||
where profileCategoryId=$session{form}{cid}");
|
||||
return www_editProfileSettings();
|
||||
}
|
||||
|
||||
|
|
@ -160,7 +170,7 @@ sub www_editProfileField {
|
|||
return WebGUI::Privilege::adminOnly() unless (WebGUI::Privilege::isInGroup(3));
|
||||
my ($output, $f, %data, %hash, $key);
|
||||
tie %data, 'Tie::CPHash';
|
||||
$output = '<h1>'.WebGUI::International::get(471).'</h1>';
|
||||
$output = '<h1>'.WebGUI::International::get(471,"WebGUI/Profile").'</h1>';
|
||||
$f = WebGUI::HTMLForm->new;
|
||||
$f->hidden("op","editProfileFieldSave");
|
||||
if ($session{form}{fid}) {
|
||||
|
|
@ -172,8 +182,21 @@ sub www_editProfileField {
|
|||
$f->text("fid",WebGUI::International::get(470));
|
||||
}
|
||||
$f->text("fieldLabel",WebGUI::International::get(472),$data{fieldLabel});
|
||||
$f->yesNo("visible",WebGUI::International::get(473),$data{visible});
|
||||
$f->yesNo("required",WebGUI::International::get(474),$data{required});
|
||||
$f->yesNo(
|
||||
-name=>"visible",
|
||||
-label=>WebGUI::International::get(473,"WebGUI/Profile"),
|
||||
-value=>$data{visible}
|
||||
);
|
||||
$f->yesNo(
|
||||
-name=>"editable",
|
||||
-value=>$data{editable},
|
||||
-label=>WebGUI::International::get(897,"WebGUI/Profile")
|
||||
);
|
||||
$f->yesNo(
|
||||
-name=>"required",
|
||||
-label=>WebGUI::International::get(474,"WebGUI/Profile"),
|
||||
-value=>$data{required}
|
||||
);
|
||||
tie %hash, 'Tie::IxHash';
|
||||
%hash = ( 'text'=>WebGUI::International::get(475),
|
||||
'textarea'=>WebGUI::International::get(476),
|
||||
|
|
@ -194,7 +217,12 @@ sub www_editProfileField {
|
|||
foreach $key (keys %hash) {
|
||||
$hash{$key} = eval $hash{$key};
|
||||
}
|
||||
$f->select("profileCategoryId",\%hash,WebGUI::International::get(489),[$data{profileCategoryId}]);
|
||||
$f->select(
|
||||
-name=>"profileCategoryId",
|
||||
-options=>\%hash,
|
||||
-label=>WebGUI::International::get(489,"WebGUI/Profile"),
|
||||
-value=>[$data{profileCategoryId}]
|
||||
);
|
||||
$f->submit;
|
||||
$output .= $f->print;
|
||||
return _submenu($output);
|
||||
|
|
@ -220,8 +248,9 @@ sub www_editProfileFieldSave {
|
|||
}
|
||||
WebGUI::SQL->write("update userProfileField set
|
||||
fieldLabel=".quote($session{form}{fieldLabel}).",
|
||||
visible='$session{form}{visible}',
|
||||
required='$session{form}{required}',
|
||||
visible=$session{form}{visible},
|
||||
required=$session{form}{required},
|
||||
editable=$session{form}{editable},
|
||||
dataType=".quote($session{form}{dataType}).",
|
||||
dataValues=".quote($session{form}{dataValues}).",
|
||||
dataDefault=".quote($session{form}{dataDefault}).",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue