prefix.$this->file."\"/>\n"; } public function show() { echo $this->src(); } public function Icon($file, $prefix) { $this->file = $file; $this->prefix = $prefix; } } class Icons { public $icons = array(); public $prefix; // Admin config public $admin_title = "Icons"; public $admin_submodules = array("Add icon" => "add", "Delete icon" => "delete"); public function admin_add($action, $vars) { global $_FILES; switch($action) { case "create": if(is_uploaded_file($_FILES['icon']['tmp_name'])) { move_uploaded_file($_FILES['icon']['tmp_name'], $this->prefix . $_FILES['icon']['name']); $i = new Icon($_FILES['icon']['name'], $this->prefix); $this->icons[$_FILES['icon']['name']] = $i; $i->show(); } else { echo "Failed to upload file: " . $icon['name'] . " to " . $icon['tmp_name'] . "\n"; } default: echo "Existing icons\n"; echo "
Are you sure you want to delete this icon?
\n"; $this->icons[$vars['icon']]->show(); $form = new Form("delete"); $form->addWidget(new Hidden($vars)); $form->addWidget(new Button("yes")); $form->render(); $form = new Form("select"); $form->addWidget(new Hidden($vars)); $form->addWidget(new Button("no")); $form->render(); break; case "delete": unlink($this->prefix.$vars['icon']); unset($this->icons[$vars['icon']]); echo "The icon has now been deleted.
\n"; case "select": default: $form = new Form("confirm"); $form->addWidget(new ImageComboBox("Icon", "icon", $icon, $this)); $form->addWidget(new Button("Delete...")); $form->render(); break; } } public function admin($sub, $action, $vars) { switch($sub) { case "add": $this->admin_add($action, $vars); break; case "delete": $this->admin_delete($action, $vars); break; } } public function Icons($prefix) { $this->prefix = $prefix; if(is_dir($prefix)) { $df = opendir($prefix); while(false !== ($file = readdir($df))) { if($file == '.' || $file == '..') continue; $icon = new Icon($file, $prefix); $this->icons[$file] = $icon; } closedir($df); } } } function icons_init() { global $ICONS_DIR; return new Icons($ICONS_DIR."/"); } ?>