Example #1
0
function addpage()
{
    $addtErrMsg = array();
    $catlist = getDetails('cats');
    $newp = new Page();
    $newp->newPageInit();
    $newp->addToCat('sidebar');
    if (isset($_POST[save])) {
        $isFormSubmitted = true;
        $content = stripslashes($_POST[content]);
        $title = stripslashes($_POST[title]);
        $newp->editTitle($title);
        $slug = $newp->slug;
        //	Fixed category adding
        $postVariables = $_POST;
        $selectedCats = array();
        foreach ($postVariables as $catKey => $categoryName) {
            if (strpos($catKey, 'check_') !== false) {
                $selectedCats[] = $categoryName;
            }
        }
        if (count($selectedCats) == 0) {
            $selectedCats[] = 'sidebar';
        }
        $newp->cats = $selectedCats;
        // $newp->commitChanges(); // dont commit yet
        // fix complete
        if ($title != '' and $content != '') {
            $newPageFile = pageDataDir($slug);
            if (!file_exists($newPageFile)) {
                //view all cats
                $newp->commitChanges();
                //debug($newp);
                runTweak('new-page', array('page-obj' => &$newp, 'page-content' => &$content));
                if (put2file($newPageFile, $content)) {
                    savepages();
                }
                $m = lt("The page was created successfully", 'page-create-success') . '<br />';
                $m .= lt("File Created") . " : " . $newPageFile . "<br />";
                $m .= lt("Content") . " : " . substr(strip_tags($content), 0, 100) . (strlen($content) > 100 ? '...' : '') . "<br />";
                MsgBox($m);
                return;
                // success
            } else {
                $addtErrMsg[] = lt("Save Failed");
                if (file_exists($newPageFile)) {
                    $addtErrMsg[] = lt("A page with similar Title already exists!!", 'similar-page-title-exists');
                }
            }
        } else {
            $addtErrMsg[] = lt("Either the title or the content is/are empty!!! Please check your input!!<br />", 'title-or-content-empty');
        }
        //die('f****d');
        //savepages();
    }
    if (count($addtErrMsg) != 0 and isset($title)) {
        //error occured
        $em = '';
        foreach ($addtErrMsg as $msg) {
            $em .= "<li>{$msg}</li>";
        }
        MsgBox(lt("Errors Occured") . " : <ul>{$em}</ul>", 'background:#FFE8E8;border:1px solid #AE0000');
    }
    //debug($addtErrMsg);
    $formAction = "?action=addpage";
    $submitButton = lt('Add Page');
    $chkboxs = checkBoxList(getDetails('cats'), $newp->cats);
    $pageTitleLabel = lt('Page Title');
    $catsLabel = lt('Categories');
    $contentLabel = lt('Content');
    $addnewpageLabel = lt('Add new Page');
    echo $te = <<<TET
\t<form action='{$formAction}' method=post class='pagemod_form'>
\t\t<h2>{$addnewpageLabel}</h2>
\t\t<table width='98%' border='0'>
\t\t  <tr>
\t\t\t<td width='20%'>{$pageTitleLabel}</td>
\t\t\t<td><input type='text' value='{$title}' name='title'></td>
\t\t\t<td align='right'><input type='submit' value='{$submitButton}' name='save'></td>
\t\t  </tr>
\t\t  <tr>
\t\t\t<td>{$catsLabel}</td>
\t\t\t<td colspan=2>{$chkboxs}</td>
\t\t  </tr>
\t\t</table>
\t\t<h2>{$contentLabel}</h2>
\t\t<table width="98%">
\t\t  <tr><td colspan=2>
\t\t\t<textarea name='content' rows=20 cols=70 id='editbox' class='editbox'>{$content}</textarea>
\t\t  </td></tr>
\t\t  <tr><td colspan=2><br /><input type='submit' value='{$submitButton}' name='save'></td></tr>
\t\t</table>
\t</form>
TET;
    runTweak('after-add-form-display');
}