function showusermod() { global $lang; global $conf; global $user; global $admin; global $site; global $userid; $site->title($lang['admin']['modifyusers']); $site->addfooter("help.php?on=admin#user", "help", $lang['menu']['help'], $lang['menu']['helpalt']); if ($_POST['cancel']) { redirect("admin.php"); } $form1 = new CodeKBForm("admin.php", "modifyuser"); $form1->addhidden("user", $userid); $form1->addtext("name", $admin->username($userid)); $form1->addlabel("name", $lang['general']['username']); $form1->setrequired("name"); $form1->addpassword("password"); $form1->addlabel("password", $lang['admin']['password']); $form1->addcheckbox("delete", $lang['admin']['deleteuser']); $form1->addsubmit("changeuser"); $form1->addcancel(); $form2 = new CodeKBForm("admin.php", "modifyuser"); $form2->addhidden("user", $userid); $groups = $admin->listgroups(); foreach ($groups as $val) { if (!is_null($val['name'])) { $form2->addcombo("group", $val['id'], $val['name']); } } $form2->addsubmit("joingroup"); $form2->addcancel(); $form3 = new CodeKBForm("admin.php", "modifyuser"); $form3->addhidden("user", $userid); $usersgroups = $admin->usersgroups($userid); foreach ($usersgroups as $val) { if (!is_null($val['name'])) { $form3->addcheckbox("group_" . $val['id'], $val['name'] . " (" . url("admin.php?group=" . $val['id'] . "&action=modifygroup", $lang['general']['modify']) . ")"); } } $form3->addsubmit("partgroup", $lang['general']['delete']); $form3->addcancel(); if ($_POST['changeuser']) { if (!$form1->fill()) { $site->addcontent(notice($lang['general']['missing'])); } else { if ($form1->value("delete")) { try { $admin->deleteuser($userid); redirect("admin.php?action=users"); } catch (Exception $e) { if ($e->getCode() == 1) { $site->addcontent(notice($lang['admin']['deleteadmin'])); } else { $site->addcontent(notice($lang['admin']['faileddeluser'])); } } } else { try { $admin->changeuser($userid, $form1->value("name"), $form1->value("password")); $site->addcontent(notice($lang['admin']['changeusersucc'])); $form1->addpassword("password", ""); } catch (Exception $e) { if ($e->getCode() == 1) { $site->addcontent(notice($lang['admin']['duplicateuser'])); $form1->setmissing("name"); } else { $site->addcontent(notice($lang['admin']['failesuserchange'])); } } } } } if ($_POST['joingroup'] && $form2->fill() && $form2->value("group")) { try { $admin->joingroup($userid, $form2->value("group")); $site->addcontent(notice($lang['admin']['joinsucc'])); $form3->addcheckbox("group_" . $form2->value("group"), $admin->groupname($form2->value("group")) . " (" . url("admin.php?group=" . $form2->value("group") . "&action=modifygroup", $lang['general']['modify']) . ")"); } catch (Exception $e) { if ($e->getCode() == 1) { $site->addcontent(notice($lang['admin']['alreadyingroup'])); } else { $site->addcontent(notice($lang['admin']['failedjoin'])); } } } if ($_POST['partgroup'] && $form3->fill()) { try { foreach ($usersgroups as $val) { if ($form3->value("group_" . $val['id'])) { $admin->partgroup($userid, $val['id']); $notice = $lang['admin']['partsucc']; $form3->remove("group_" . $val['id']); } } } catch (Exception $e) { $notice = $lang['admin']['failedpart']; } $site->addcontent(notice($notice)); } $dialog = new CodeKBTemplate("dialog"); $dialog->push("legend", $lang['admin']['modifyusers']); $dialogitem1 = new CodeKBTemplate("dialogitem"); $content = $form1->head(); $content .= $lang['admin']['changeuserexplain'] . "<br /><br />\n"; $dialogitem1->push("head", $content); $dialogitem1->push("content1", $form1->get()); $dialogitem1->push("tail", $form1->tail()); $dialogitem2 = new CodeKBTemplate("dialogitem"); $content = $form2->head(); $content .= $lang['admin']['joinuserexplain'] . "<br /><br />\n"; $dialogitem2->push("head", $content); $dialogitem2->push("content1", $form2->get()); $dialogitem2->push("tail", $form2->tail()); $dialogitem3 = new CodeKBTemplate("dialogitem"); $content = $form3->head(); $content .= $lang['admin']['partuserexplain'] . "<br /><br />\n"; $dialogitem3->push("head", $content); $content = "<div class = \"forms\">"; $content .= $form3->get(); $content .= "</div>"; $dialogitem3->push("content1", $content); $dialogitem3->push("tail", $form3->tail()); $dialogcode = $dialogitem1->__toString(); $dialogcode .= $dialogitem2->__toString(); $dialogcode .= $dialogitem3->__toString(); $dialog->push("content", $dialogcode); $site->addcontent($dialog); return true; }
function showregister() { global $lang; global $site; global $user; $site->title($lang['register']['title']); $site->addfooter("help.php?on=login", "help", $lang['menu']['help'], $lang['menu']['helpalt']); if ($_POST['cancel']) { redirect("home.php"); } $form = new CodeKBForm("login.php", "register"); $form->addtext("user"); $form->addlabel("user", $lang['general']['username']); $form->setrequired("user"); $form->addpassword("password"); $form->addlabel("password", $lang['general']['password']); $form->setrequired("password"); $form->addpassword("password2"); $form->addlabel("password2", $lang['register']['passwordagain']); $form->setrequired("password2"); $form->addsubmit(); $form->addcancel(); if ($_POST['submit']) { if (!$form->fill()) { $site->addcontent(notice($lang['general']['missing'])); } else { if ($form->value("password") != $form->value("password2")) { $site->addcontent(notice($lang['register']['wrongpass'])); $form->setmissing("password"); $form->setmissing("password2"); } else { try { $user->register($form->value("user"), $form->value("password")); redirect("login.php?action=registered"); } catch (Exception $e) { if ($e->getCode() == 1) { $site->addcontent(notice($lang['register']['duplicate'])); $form->setmissing("user"); $form->setmissing("password"); $form->setmissing("password2"); } else { $site->addcontent(notice($lang['register']['failed'])); } } } } } $dialog = new CodeKBTemplate("dialog"); $dialog->push("legend", $lang['register']['title']); $content = $form->head(); $content .= $lang['register']['description'] . "<br /><br />\n"; $content .= $form->get(); $content .= $form->tail(); $dialog->push("content", $content); $site->addcontent($dialog); return true; }