\n"; $str .= "
Looking ok?
"; $form = new Form("add"); $form->addWidget(new Hidden($vars)); $form->addWidget(new Button("yes")); $form->render(); $form = new Form("retry"); $form->addWidget(new Hidden($vars)); $form->addWidget(new Button("no")); $form->render(); break; case "retry": $name = $vars["name"]; $image = $vars["image"]; $startyear = $vars["startyear"]; $stopyear = $vars["stopyear"]; $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(); break; } } public function admin_edit($action, $vars) { global $MEMBERS_DIR; switch($action) { case "add": $tags = $this->getTagsFromArray($vars, "tags_"); $this->members[$vars["memberid"]]->show(); $this->members[$vars["memberid"]]->name = $vars["name"]; $this->members[$vars["memberid"]]->image = $vars["image"]; $this->members[$vars["memberid"]]->startyear = $vars["startyear"]; $this->members[$vars["memberid"]]->stopyear = $vars["stopyear"]; $this->members[$vars["memberid"]]->tags = $tags; $this->write(); echo "\"" . $this->members[$vars["memberid"]]->name . "\" has now been edited."; break; case "preview": $tags = $this->getTagsFromArray($vars, "tags_"); $member = new Member($vars["memberid"], $vars["name"], $vars["image"], $vars["startyear"], $vars["stopyear"], $tags, $this->tags); echo "Looking ok?
"; $form = new Form("add"); $form->addWidget(new Hidden($vars)); $form->addWidget(new Button("yes")); $form->render(); $form = new Form("retry"); $form->addWidget(new Hidden($vars)); $form->addWidget(new Button("no")); $form->render(); break; case "edit": case "retry": if(isset($vars["name"])) $name = $vars["name"]; else $name = $this->members[$vars["memberid"]]->name; if(isset($vars["image"])) $image = $vars["image"]; else $image = $this->members[$vars["memberid"]]->image; if(isset($vars["startyear"])) $startyear = $vars["startyear"]; else $startyear = $this->members[$vars["memberid"]]->startyear; 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(); break; case "select": default: $memberlist = array(); foreach($this->members as $member) { $memberlist[$member->name] = sprintf("%d", $member->id); } $form = new Form("edit"); $form->addWidget(new ComboBox("Edit this member:", "memberid", "", $memberlist)); $form->addWidget(new Button("Edit...")); $form->render(); break; } } 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) { case "add": $this->admin_add($action, $vars); break; case "edit": $this->admin_edit($action, $vars); break; case "tags": $this->admin_tags($action, $vars); break; } } public function run($params) { $str = ""; foreach($this->members as $member) { $str .= $member->show(); } return $str; } public function add($member) { $key = $member->id; $this->members[$key] = $member; } public function getNextID() { $maxid = -1; foreach($this->members as $member) { if($member->id > $maxid) $maxid = $member->id; } return $maxid + 1; } public function write() { $fp = fopen($this->file, "w"); fwrite($fp, "\n"); fwrite($fp, "