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:
JT Smith 2003-04-12 22:52:31 +00:00
parent 29406354f3
commit 0edcfad5f5
3 changed files with 117 additions and 71 deletions

View file

@ -17,7 +17,26 @@ INSERT INTO template VALUES (4,'Descriptive','<tmpl_if displayTitle>\r\n <h1>
INSERT INTO template VALUES (3,'Ordered List','<tmpl_if displayTitle>\r\n <h1><tmpl_var title></h1>\r\n</tmpl_if>\r\n\r\n<tmpl_if description>\r\n <tmpl_var description><p />\r\n</tmpl_if>\r\n\r\n<tmpl_if session.var.adminOn><tmpl_if canEdit>\r\n <a href=\"<tmpl_var addlink.url>\"><tmpl_var addlink.label></a><p />\r\n</tmpl_if></tmpl_if>\r\n\r\n<ol>\r\n<tmpl_loop link_loop>\r\n <li>\r\n <tmpl_if session.var.adminOn><tmpl_if canEdit>\r\n <tmpl_var link.controls>\r\n </tmpl_if> </tmpl_if>\r\n\r\n <a href=\"<tmpl_var link.url>\"\r\n <tmpl_if link.newwindow>\r\n target=\"_blank\"\r\n </tmpl_if>\r\n ><span class=\"linkTitle\"><tmpl_var link.name></span></a>\r\n\r\n <tmpl_if link.description>\r\n - <tmpl_var link.description>\r\n </tmpl_if>\r\n </li>\r\n</tmpl_loop>\r\n</ol>','LinkList');
INSERT INTO template VALUES (1,'Default Link List','<tmpl_if displayTitle>\r\n <h1><tmpl_var title></h1>\r\n</tmpl_if>\r\n\r\n<tmpl_if description>\r\n <tmpl_var description><p />\r\n</tmpl_if>\r\n\r\n<tmpl_if session.var.adminOn>\r\n<tmpl_if canEdit>\r\n <a href=\"<tmpl_var addlink.url>\"><tmpl_var addlink.label></a><p />\r\n</tmpl_if>\r\n</tmpl_if>\r\n\r\n<tmpl_loop link_loop>\r\n <tmpl_if session.var.adminOn>\r\n <tmpl_if canEdit>\r\n <tmpl_var link.controls>\r\n </tmpl_if>\r\n </tmpl_if>\r\n &middot;\r\n <a href=\"<tmpl_var link.url>\"\r\n <tmpl_if link.newwindow>\r\n target=\"_blank\"\r\n </tmpl_if>\r\n ><span class=\"linkTitle\"><tmpl_var link.name></span></a>\r\n\r\n <tmpl_if link.description>\r\n - <tmpl_var link.description>\r\n </tmpl_if>\r\n <br/>\r\n</tmpl_loop>\r\n','LinkList');
INSERT INTO template VALUES (2,'Unordered List','<tmpl_if displayTitle>\r\n <h1><tmpl_var title></h1>\r\n</tmpl_if>\r\n\r\n<tmpl_if description>\r\n <tmpl_var description><p />\r\n</tmpl_if>\r\n\r\n<tmpl_if session.var.adminOn><tmpl_if canEdit>\r\n <a href=\"<tmpl_var addlink.url>\"><tmpl_var addlink.label></a><p />\r\n</tmpl_if></tmpl_if>\r\n\r\n<ul>\r\n<tmpl_loop link_loop>\r\n<li>\r\n <tmpl_if session.var.adminOn><tmpl_if canEdit>\r\n <tmpl_var link.controls>\r\n </tmpl_if></tmpl_if>\r\n \r\n <a href=\"<tmpl_var link.url>\"\r\n <tmpl_if link.newwindow>\r\n target=\"_blank\"\r\n </tmpl_if>\r\n ><span class=\"linkTitle\"><tmpl_var link.name></span></a>\r\n\r\n <tmpl_if link.description>\r\n - <tmpl_var link.description>\r\n </tmpl_if>\r\n </li>\r\n</tmpl_loop>\r\n</u>','LinkList');
alter table userProfileCategory add column visible int not null default 1;
alter table userProfileCategory add column editable int not null default 1;
update userProfileCategory set visible=0 where profileCategoryId=4;
alter table userProfileField add column editable int not null default 1;
update userProfileField set editable=visible;
update international set namespace='WebGUI/Profile' where namespace='WebGUI' and internationalId=473;
delete from international where languageId=1 and namespace='WebGUI/Profile' and internationalId=897;
insert into international (internationalId,languageId,namespace,message,lastUpdated) values (897,1,'WebGUI/Profile','Editable?', 1050167573);
update international set namespace='WebGUI/Profile' where namespace='WebGUI' and internationalId=471;
update international set namespace='WebGUI/Profile' where namespace='WebGUI' and internationalId=468;
update international set namespace='WebGUI/Profile' where namespace='WebGUI' and internationalId=474;
update international set namespace='WebGUI/Profile' where namespace='WebGUI' and internationalId=489;
update international set namespace='WebGUI/Profile' where namespace='WebGUI' and internationalId=491;
update international set namespace='WebGUI/Profile' where namespace='WebGUI' and internationalId=490;
update international set namespace='WebGUI/Profile' where namespace='WebGUI' and internationalId=787;
update international set namespace='WebGUI/Profile' where namespace='WebGUI' and internationalId=788;
update international set namespace='WebGUI/Profile' where namespace='WebGUI' and internationalId=789;
update international set namespace='WebGUI/Profile' where namespace='WebGUI' and internationalId=790;
update international set namespace='WebGUI/Profile' where namespace='WebGUI' and internationalId=466;
update international set namespace='WebGUI/Profile' where namespace='WebGUI' and internationalId=467;

View file

@ -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};

View file

@ -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 .= '&nbsp;&nbsp;&nbsp;&nbsp;<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 .= '&nbsp;&nbsp;&nbsp;&nbsp;<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}).",