Exemplo n.º 1
0
function main()
{
    global $lang;
    global $fileid;
    global $catid;
    global $user;
    global $site;
    global $category;
    global $file;
    if (!is_bool($catid) && is_numeric($catid)) {
        try {
            $category = new CodeKBCategory($catid, $user);
        } catch (Exception $e) {
            $site->addcontent(notice($lang['category']['nosuchcat']));
            return false;
        }
    }
    try {
        $file = new CodeKBFile($fileid, $user);
    } catch (Exception $e) {
        $site->addcontent(notice($lang['file']['nosuchfile']));
        return false;
    }
    if (!$file->downloadable()) {
        $site->addcontent(notice($lang['file']['nosuchfile']));
        return false;
    }
    if ($category) {
        $site->navigation($category, $file->entry());
        $catid = $category->id();
        $site->catid($catid);
    }
    return true;
}
Exemplo n.º 2
0
 private function delete()
 {
     if (!$this->_user->entrycan("delentry", $this)) {
         return false;
     }
     $db = new CodeKBDatabase();
     $db->dosql("SELECT id " . "FROM files " . "WHERE entry = {$db->number($this->_id)}");
     while ($val = $db->row()) {
         $file = new CodeKBFile($val['id'], $this->_user);
         if (!$file->delete(true)) {
             return false;
         }
         unset($file);
     }
     $db->start();
     $db->dosql("DELETE FROM entry_cat " . "WHERE entry = {$db->number($this->_id)}");
     $db->dosql("DELETE FROM entries " . "WHERE id = {$db->number($this->_id)}");
     $db->commit();
     if ($db->success()) {
         return true;
     }
     throw new CodeKBException(__METHOD__, "entry", "faileddel");
 }
Exemplo n.º 3
0
function showfiles()
{
    global $lang;
    global $conf;
    global $user;
    global $site;
    global $category;
    global $entry;
    $site->title($lang['entry']['files']);
    $site->addfooter("help.php?on=file", "help", $lang['menu']['help'], $lang['menu']['helpalt']);
    if ($category) {
        $cat = $category->id();
    }
    if (!$user->entrycan("changeentry", $entry)) {
        $site->addcontent(notice($lang['entry']['nochangeallowed']));
        return false;
    }
    if ($_POST['cancel']) {
        redirect("entry.php?id=" . $entry->id() . "&cat=" . $cat);
    }
    $form1 = new CodeKBForm("entry.php", "files");
    $form1->addhidden("id", $entry->id());
    $form1->addhidden("cat", $cat);
    $form1->addfile("upload");
    $form1->addlabel("upload", $lang['file']['upload']);
    $form1->addcombo("highlight", $conf['highlight']['binary']);
    while ($language = next($conf['highlight']['languages'])) {
        $form1->addcombo("highlight", $language, null, $language == "text");
    }
    $form1->addlabel("highlight", $lang['file']['language']);
    $db = new CodeKBDatabase();
    $db->dosql("SELECT name, symbol " . "FROM symbols " . "WHERE symbol LIKE 'type_%'");
    while ($val = $db->row()) {
        $form1->addradio("symbol", $val['name'], icon($val['name'], $val['name']), $val['name'] == "Unkown", false);
    }
    $form1->addsubmit("addfile");
    $form1->addcancel();
    $form2 = new CodeKBForm("entry.php", "files");
    $form2->addhidden("id", $entry->id());
    $form2->addhidden("cat", $cat);
    $filesofentry = $entry->listfiles();
    foreach ($filesofentry as $val) {
        $form2->addcheckbox("file_" . $val['id'], icon($val['symbol'], $val['name']) . " " . $val['name'] . " (" . url("file.php?id=" . $val['id'] . "&cat=" . $cat . "&action=modify", $lang['general']['modify']) . ")");
    }
    $form2->addsubmit("removefile", $lang['general']['delete']);
    $form2->addcancel();
    if ($_POST['addfile'] && $form1->fill()) {
        try {
            $ret = $entry->addfile("upload", $form1->value("highlight"), $form1->value("symbol"));
            $newfile = new CodeKBFile($ret, $user);
            $site->addcontent(notice($lang['file']['addsucc']));
            $form2->addcheckbox("file_" . $newfile->id(), icon($newfile->symbol(), $newfile->name()) . " " . $newfile->name() . " (" . url("file.php?id=" . $newfile->id() . "&cat=" . $cat . "&action=modify", $lang['general']['modify']) . ")");
            unset($newfile);
        } catch (Exception $e) {
            if ($e->getCode() == 1) {
                $site->addcontent(notice($lang['file']['uploadfailed']));
            } else {
                $site->addcontent(notice($lang['file']['failedadd']));
            }
        }
    }
    if ($_POST['removefile'] && $form2->fill()) {
        foreach ($filesofentry as $val) {
            try {
                if ($form2->value("file_" . $val['id']) == "1") {
                    $tmpfile = new CodeKBFile($val['id'], $user);
                    $tmpfile->delete();
                    unset($tmpfile);
                    $notice = $lang['file']['delsucc'];
                    $form2->remove("file_" . $val['id']);
                }
            } catch (Exception1 $e) {
                $notice = $lang['file']['failedremove'];
                break;
            }
        }
        $site->addcontent(notice($notice));
    }
    $dialog = new CodeKBTemplate("dialog");
    $dialog->push("legend", $lang['entry']['files']);
    $dialogcode = "";
    $dialogitem1 = new CodeKBTemplate("dialogitem");
    $content = $form1->head();
    $content .= $lang['file']['addexplain'] . "<br /><br />\n";
    $dialogitem1->push("head", $content);
    $dialogitem1->push("content1", $form1->get());
    $dialogitem1->push("tail", $form1->tail());
    $dialogcode .= $dialogitem1->__toString();
    $content = $form2->head();
    $content .= $lang['file']['removeexplain'] . "<br /><br />\n";
    $dialogitem2 = new CodeKBTemplate("dialogitem");
    $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;
}