Exemplo n.º 1
0
 public function navigation(&$category, &$entry = null)
 {
     global $lang;
     $navigate = new CodeKBTemplate("navigation");
     $naviid = $category->id();
     while ($naviid != 0) {
         $curcat = new CodeKBCategory($naviid, $this->_user);
         $navi[] = array("id" => $curcat->id(), "name" => $curcat->name());
         $naviid = $curcat->parent();
         unset($curcat);
     }
     $content = "";
     $content .= url("category.php", $lang['category']['root'], $lang['category']['root']) . "\n";
     while (is_array($navi) && ($val = array_pop($navi))) {
         $content .= " / " . url("category.php?id=" . $val['id'], htmlentities($val['name']), $val['name']) . "\n";
     }
     if ($entry) {
         $content .= " / <em>" . url("entry.php?id=" . $entry->id() . "&cat=" . $category->id(), htmlentities($entry->name()), $entry->name()) . "</em>\n";
     }
     $navigate->push("navi", $content);
     $this->_navigation = $navigate;
     unset($navigate);
 }
Exemplo n.º 2
0
function showlinks()
{
    global $lang;
    global $user;
    global $site;
    global $category;
    global $entry;
    $site->title($lang['entry']['link']);
    $site->addfooter("help.php?on=entry#link", "help", $lang['menu']['help'], $lang['menu']['helpalt']);
    if (!$user->entrycan("delentry", $entry) && !$user->entrycan("addentry", $entry)) {
        $site->addcontent(notice($lang['entry']['nochangeallowed']));
        return false;
    }
    if ($category) {
        $cat = $category->id();
    }
    if ($_POST['cancel']) {
        redirect("entry.php?id=" . $entry->id() . "&cat=" . $cat);
    }
    if ($user->entrycan("addentry", $entry)) {
        $form1 = new CodeKBForm("entry.php", "link");
        $form1->addhidden("id", $entry->id());
        $form1->addhidden("cat", $cat);
        $tmpcat = new CodeKBCategory(0, $user);
        if ($user->can("addentry", $tmpcat)) {
            $form1->addcombo("newcat", "0", $lang['category']['root']);
        }
        $array = $tmpcat->listcategories("name", 1);
        foreach ($array as $val) {
            if ($user->can("addentry", $val['id'])) {
                $form1->addcombo("newcat", $val['id'], str_repeat("-", $val['reclevel'] * 2) . " " . $val['name']);
            }
        }
        unset($tmpcat);
        $form1->addlabel("newcat", $lang['entry']['linkadd']);
        $form1->addsubmit("addlink");
        $form1->addcancel();
    }
    if ($user->entrycan("delentry", $entry)) {
        $form2 = new CodeKBForm("entry.php", "link");
        $form2->addhidden("id", $entry->id());
        $form2->addhidden("cat", $cat);
        $catsofentry = $entry->categories();
        foreach ($catsofentry as $val) {
            $thiscat = new CodeKBCategory($val, $user);
            $form2->addcheckbox("cat_" . $thiscat->id(), $thiscat->name());
            unset($thiscat);
        }
        $form2->addsubmit("unlink", $lang['general']['delete']);
        $form2->addcancel();
    }
    if ($_POST['addlink'] && $form1->fill()) {
        try {
            $newcat = new CodeKBCategory($form1->value("newcat"), $user);
            if ($entry->addlink($form1->value("newcat"))) {
                $site->addcontent(notice(phrasereplace($lang['entry']['linkaddsucc'], "%1%", $newcat->name())));
                if ($form2) {
                    $form2->addcheckbox("cat_" . $newcat->id(), $newcat->name());
                }
            } else {
                $site->addcontent(notice($lang['entry']['failedchange']));
            }
            unset($newcat);
        } catch (Exception $e) {
            if ($e->getCode() == 1) {
                $site->addcontent(notice($lang['entry']['duplicate']));
                $form1->setmissing("newcat");
            } else {
                $site->addcontent(notice($lang['entry']['failedchange']));
            }
        }
    }
    if ($_POST['unlink'] && is_object($form2) && $form2->fill()) {
        $id = $entry->id();
        foreach ($catsofentry as $val) {
            if ($form2->value("cat_" . $val) == "1") {
                try {
                    $entry->delink($val);
                    $notice = $lang['entry']['linkremovesucc'];
                    $form2->remove("cat_" . $val);
                } catch (Exception $e) {
                    $form2->setmissing("cat_" . $val);
                    $notice = $lang['entry']['failedunlink'];
                    break;
                }
            }
        }
        if (!$user->entrycan("see", $entry, false)) {
            redirect("category.php?id=" . $cat);
        }
        $site->addcontent(notice($notice));
    }
    $dialog = new CodeKBTemplate("dialog");
    $dialog->push("legend", $lang['entry']['link']);
    $dialogcode = "";
    if ($form1) {
        $dialogitem1 = new CodeKBTemplate("dialogitem");
        $content = $form1->head();
        $content .= $lang['entry']['linkaddexplain'] . "<br /><br />\n";
        $dialogitem1->push("head", $content);
        $dialogitem1->push("content1", $form1->get());
        $dialogitem1->push("tail", $form1->tail());
        $dialogcode .= $dialogitem1->__toString();
    }
    if ($form2) {
        $dialogitem2 = new CodeKBTemplate("dialogitem");
        $content = $form2->head();
        $content .= $lang['entry']['linkremoveexplain'] . "<br /><br />\n";
        $dialogitem2->push("head", $content);
        $content = "<div class = \"forms\">\n";
        $content .= $form2->get();
        $content .= "</div>";
        $dialogitem2->push("content1", $content);
        $dialogitem2->push("tail", $form2->tail());
        $dialogcode .= $dialogitem2->__toString();
    }
    $dialog->push("content", $dialogcode);
    $site->addcontent($dialog);
    return true;
}