summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rw-r--r--utils/modules/members.php86
1 files changed, 71 insertions, 15 deletions
diff --git a/utils/modules/members.php b/utils/modules/members.php
index e5e4d91..2cd309c 100644
--- a/utils/modules/members.php
+++ b/utils/modules/members.php
@@ -12,6 +12,7 @@ class Member {
public $startyear;
public $stopyear;
public $tags;
+ public $tagnames;
public function show()
{
@@ -21,10 +22,10 @@ class Member {
$str .= " <img alt=\"member\" class=\"member_image\" src=\"" . $MEMBERS_DIR."/".$this->image."\"/>\n";
$str .= " <div class=\"member_startyear\">Member since: " . $this->startyear . "</div>\n";
foreach($this->tags as $name => $val) {
- $str .= " <div class=\"member_tag\">\n";
- $str .= " <div class=\"member_tag_name\">".$name."</div>\n";
+ $str .= " <div class=\"member_tag\"><div class=\"member_tags_".$name."\">\n";
+ $str .= " <div class=\"member_tag_name\">".$this->tagnames[$name]."</div>\n";
$str .= " <div class=\"member_tag_value\">".$val."</div>\n";
- $str .= " </div>\n";
+ $str .= " </div></div>\n";
}
$str .= "</div>\n";
return $str;
@@ -43,7 +44,7 @@ class Member {
fwrite($fp, " </member>\n");
}
- public function Member($id, $name, $image, $startyear, $stopyear, $tags)
+ public function Member($id, $name, $image, $startyear, $stopyear, $tags, $tagnames)
{
$this->id = $id;
$this->name = $name;
@@ -51,6 +52,7 @@ class Member {
$this->startyear = $startyear;
$this->stopyear = $stopyear;
$this->tags = $tags;
+ $this->tagnames = $tagnames;
}
}
@@ -58,11 +60,13 @@ class Members {
private $file;
private $members = array();
+ private $tags = array();
// Admin config
public $admin_title = "Members";
public $admin_submodules = array("Add Member" => "add",
- "Edit Member" => "edit");
+ "Edit Member" => "edit",
+ "Tag Editor" => "tags");
public function admin_add($action, $vars)
{
@@ -70,18 +74,18 @@ class Members {
switch($action) {
case "add":
- $tags = array();
+ $tags = $this->getTagsFromArray($vars, "tags_");
$member = new Member($this->getNextID(), $vars["name"], $vars["image"],
- $vars["startyear"], $vars["stopyear"], $tags);
+ $vars["startyear"], $vars["stopyear"], $tags, $this->tags);
echo "\"" .$member->name . "\" has now been added.";
$this->add($member);
$this->write();
break;
case "preview":
- $tags = array();
+ $tags = $this->getTagsFromArray($vars, "tags_");
$member = new Member($this->getNextID(), $vars["name"], $vars["image"],
- $vars["startyear"], $vars["stopyear"], $tags);
+ $vars["startyear"], $vars["stopyear"], $tags, $this->tags);
echo "<div class=\"preview\">\n";
echo "<div class=\"content\">\n";
echo $member->show();
@@ -104,12 +108,15 @@ class Members {
$image = $vars["image"];
$startyear = $vars["startyear"];
$stopyear = $vars["stopyear"];
- $tags = array();
+ $tags = $this->getTagsFromArray($vars, "tags_");
default:
$form = new Form("preview");
$form->addWidget(new LineEdit("Name", "name", $name));
$form->addWidget(new LineEdit("Start Year", "startyear", $startyear));
$form->addWidget(new LineEdit("Stop Year (if no longer a member)", "stopyear", $stopyear));
+ foreach($this->tags as $id => $title) {
+ $form->addWidget(new LineEdit($title, "tags_".$id, $tags[$id]));
+ }
$form->addWidget(new ImageComboBox("Image", "image", $image, new Icons($MEMBERS_DIR."/")));
$form->addWidget(new Button("Add member"));
$form->render();
@@ -123,7 +130,7 @@ class Members {
switch($action) {
case "add":
- $tags = array();
+ $tags = $this->getTagsFromArray($vars, "tags_");
$this->members[$vars["memberid"]]->show();
$this->members[$vars["memberid"]]->name = $vars["name"];
$this->members[$vars["memberid"]]->image = $vars["image"];
@@ -135,9 +142,9 @@ class Members {
break;
case "preview":
- $tags = array();
+ $tags = $this->getTagsFromArray($vars, "tags_");
$member = new Member($vars["memberid"], $vars["name"], $vars["image"],
- $vars["startyear"], $vars["stopyear"], $tags);
+ $vars["startyear"], $vars["stopyear"], $tags, $this->tags);
echo "<div class=\"preview\">\n";
echo "<div class=\"content\">\n";
echo $member->show();
@@ -166,11 +173,18 @@ class Members {
if(isset($vars["stopyear"])) $stopyear = $vars["stopyear"];
else $stopyear = $this->members[$vars["memberid"]]->stopyear;
+ // HACK, this should work, but we should check on the tags_ vars instead.
+ if(isset($vars["name"])) $tags = $this->getTagsFromArray($vars, "tags_");
+ else $tags = $this->members[$vars["memberid"]]->tags;
+
$form = new Form("preview");
$form->addWidget(new Hidden($vars));
$form->addWidget(new LineEdit("Name", "name", $name));
$form->addWidget(new LineEdit("Start Year", "startyear", $startyear));
$form->addWidget(new LineEdit("Stop Year (if no longer a member)", "stopyear", $stopyear));
+ foreach($this->tags as $id => $title) {
+ $form->addWidget(new LineEdit($title, "tags_".$id, $tags[$id]));
+ }
$form->addWidget(new ImageComboBox("Image", "image", $image, new Icons($MEMBERS_DIR."/")));
$form->addWidget(new Button("Preview"));
$form->render();
@@ -191,6 +205,37 @@ class Members {
}
}
+ public function admin_tags($action, $vars)
+ {
+ switch($action) {
+ case "update":
+ global $taglist;
+ $this->tags = ListEditor::splitValues($taglist);
+ $this->write();
+ break;
+
+ default:
+ $form = new Form("update");
+ $form->addWidget(new ListEditor("Tags", "taglist",
+ new LineEdit("Title (must not contain ':')", "title"),
+ new LineEdit("ID (must only contains letters a-z)", "id"),
+ $this->tags));
+ $form->addWidget(new Button("Update"));
+ $form->render();
+ break;
+ }
+ }
+
+ public function getTagsFromArray($array, $prefix)
+ {
+ $out = array();
+ foreach($array as $name => $value) {
+ if(strpos($name, $prefix) !== FALSE && strpos($name, $prefix) == 0)
+ $out[substr($name, strlen($prefix))] = $value;
+ }
+ return $out;
+ }
+
public function admin($sub, $action, $vars)
{
switch($sub) {
@@ -201,6 +246,10 @@ class Members {
case "edit":
$this->admin_edit($action, $vars);
break;
+
+ case "tags":
+ $this->admin_tags($action, $vars);
+ break;
}
}
@@ -232,7 +281,7 @@ class Members {
$fp = fopen($this->file, "w");
fwrite($fp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
- fwrite($fp, "<members>\n");
+ fwrite($fp, "<members tags=\"".htmlspecialchars(serialize($this->tags), ENT_QUOTES, "UTF-8")."\">\n");
foreach($this->members as $member) {
$member->write($fp);
}
@@ -246,6 +295,12 @@ class Members {
$dom = new DomDocument;
$dom->preserveWhiteSpace = FALSE;
$dom->load($this->file);
+
+ $ts = $dom->getElementsByTagName('members');
+ foreach($ts as $t) {
+ $this->tags = unserialize(htmlspecialchars_decode($t->getAttribute('tags'), ENT_QUOTES));
+ }
+
$params = $dom->getElementsByTagName('member');
foreach ($params as $param) {
@@ -260,7 +315,8 @@ class Members {
$param->getAttribute('image'),
$param->getAttribute('startyear'),
$param->getAttribute('stopyear'),
- $tags);
+ $tags,
+ $this->tags);
$this->add($member);
}
}