Example #1
0
function newArticle()
{
    $results = array();
    $results['pageTitle'] = "New Article";
    $results['formAction'] = "newArticle";
    if (isset($_POST['saveChanges'])) {
        // User has posted the article edit form: save the new article
        $article = new Article();
        $article->storeFormValues($_POST);
        $article->insert();
        if (isset($_FILES['image'])) {
            $article->storeUploadedImage($_FILES['image']);
        }
        header("Location: admin.php?status=changesSaved");
    } elseif (isset($_POST['cancel'])) {
        // User has cancelled their edits: return to the article list
        header("Location: admin.php");
    } else {
        // User has not posted the article edit form yet: display the form
        $results['article'] = new Article();
        $data = Category::getList();
        $results['categories'] = $data['results'];
        require TEMPLATE_PATH . "/admin/editArticle.php";
    }
}
Example #2
0
function newArticle()
{
    $results = array();
    $results['pageTitle'] = "New Article";
    $results['formAction'] = "newArticle";
    if (isset($_POST['saveChanges'])) {
        // USer has posted the article edit form: save the new Article
        $article = new Article();
        $article->storeFormValues($_POST);
        $article->insert();
        // This checks that the 'image' element exists in the $_FILES array and, if it does exist,
        // it calls the Article object's storeUploadedImage() method, passing in the
        // $_FILES['image'] element, to store the image and create the thumbnail.
        if (isset($_FILES['image'])) {
            $article->storeUploadedImage($_FILES['image']);
        }
        header("Location: admin.php?status=changesSaved");
    } elseif (isset($_POST['cancel'])) {
        // User ha cancelled their edits: return to the article list.
        header("Location: admin.php");
    } else {
        // User has not posted the article edit form yet: display the form
        $results['article'] = new Article();
        require TEMPLATE_PATH . "/admin/editArticle.php";
    }
}
Example #3
0
 public function insert(&$data)
 {
     parent::insert($data);
     if ($this->id) {
         if (isset($data['price']) && $data['price']) {
             $this->insertItem(PRICE, preg_replace('/\\D/', '', $data['price']));
         }
         return $this->get();
     }
     return $this;
 }
Example #4
0
 public function insert(&$data, $userId = 0, $slug = '')
 {
     $poll = parent::insert($data);
     if ($poll->id) {
         foreach ($data['opt'] as $opt) {
             if ($opt) {
                 self::$dbh->query('INSERT INTO poll_opt (article_id, name) VALUES (?, ?)', array($poll->id, $opt));
             }
         }
     }
     return $poll->get();
 }
Example #5
0
 public function insert(&$data)
 {
     parent::insert($data);
     if ($this->id) {
         if (isset($data['question']) && $data['question']) {
             $this->insertItem(QUESTION, $data['question']);
         }
         if (isset($data['alias']) && $data['alias']) {
             $this->insertItem(ALIAS, $data['alias']);
         }
         return $this->get();
     }
     return $this;
 }
Example #6
0
function newArticle()
{
    $results = array();
    $results['pageTitle'] = "New Article";
    $results['formAction'] = "newArticle";
    if (isset($_POST['saveChanges'])) {
        $article = new Article();
        $article->storeFormValues($_POST);
        $article->insert();
        header("Location: admin.php?status=changesSaved");
    } elseif (isset($_POST['cancel'])) {
        header("Location: admin.php");
    } else {
        $results['article'] = new Article();
        require TEMPLATE_PATH . "/admin/editArticle.php";
    }
}
Example #7
0
function newArticle()
{
    $results = array();
    $results['pageTitle'] = "New Article";
    $results['formAction'] = "newArticle";
    if (isset($_POST['saveChanges'])) {
        //user has posted the article edit form: save the new article
        $article = new Article();
        $article->storeFormValues($_POST);
        $article->insert();
        header("Location: admin.php?status=changesSaved");
    } elseif (isset($_POST['cancel'])) {
        //user has cancelled their edit: return to the article lists
        header("Location: admin.php");
    } else {
        //user has not posted the article edit form yet: display the form
        $results['article'] = new Article();
        require "templates/admin/editArticle.php";
    }
}
Example #8
0
function newArticle()
{
    $results = array();
    $results['pageTitle'] = "New Article | The Blag";
    $results['formAction'] = "newArticle";
    /*so this is going to be interpreted down the line as a conditional to determine what exactly it is I'm doing. 
      I'll declare $results['formaction'] = "editArticle" in the editArticle() function, and then write a conditional based on these in the front-end */
    if (isset($_POST['saveChanges'])) {
        /*this isn't something to do with new articles (i.e $_POST['submit']) because I'll be using a lot of the same structure for both editArticle() and newArticle(). 
          Think about it: editing an article is just (at the end of the day) changing values in my SQL database. Creating a new article is the same thing, except rather than changing some words in a paragraph, I'm changing null values to set values. 
          It's a little different in that editArticle() uses the update() function in Article.php whereas newArticle needs to set an entirely new ID, but everything I am doing is just changing the information in the database */
        $article = new Article();
        #this takes advantage of my Articles class
        $article->storeFormValues($_POST);
        #This is the bridge from HTTP to PHP, and stores the POST in my article class.
        $article->insert();
        /* so my $article variable in a way contains all of Article.php. I can just call the variable->a function as if I were in Article.php. 
           Remember insert()? It puts the values set in Article.php (right now the POST from the user) into the database under a new ID */
        $_SESSION['id'] = $_POST['id'];
        //this is for the mail stuff
        $_SESSION['title'] = $_POST['title'];
        //same
        User::newMail();
        //same
        header("Location: admin.php?status=changesSaved");
        /* so this GET (remember, gets are in the URL in the format ~.php?key=value. ) is gonna be caught later down in the code. 
           Basically, we reload admin.php (and its switchyard) and display a little popup. Tiny bby popup. smol. */
    } elseif (isset($_POST['cancel'])) {
        #so this is gonna be determined by a "cancel changes" or some such button on the front end.
        header("Location: admin.php");
        /* since I do all of the server stuff in its own functions, as long as I don't call those functions no changes can be made to my database. 
           Since they depend on POSTs, if I just reload admin.php without POSTing anything it will work just fine to cancel changing the article */
    } else {
        #so if the user has neither canceled nor posted the article form yet
        $results['article'] = new Article();
        #declares a new Article, which doesn't sound like I need to explain it until:
        require TEMPLATE_PATH . "/admin/editArticle.php";
        /*so this will display the HTML n stuff in the (yet to be made) editArticle.php code on the page, and since I just created a new Article, it displays that one, 
          which is empty, waiting for me to do my type-y type thing */
    }
}
Example #9
0
function newArticle()
{
    $results = array();
    $results['pageTitle'] = "Новая статья";
    $results['formAction'] = "newArticle";
    $results['formActionParams'] = array();
    if (isset($_POST['saveChanges'])) {
        // Пользователь заполнил форму ввода статьи: сохраняем новую статью.
        $article = new Article();
        $article->storeFormValues($_POST);
        $article->insert();
        //header("Location: index.php?action=archive&status=changesSaved");
        Notification::setStatus('changesSaved');
        Route::redirectTo('archive');
    } elseif (isset($_POST['cancel'])) {
        // Пользователь отменил правку. Возвращаемся в список статей.
        Route::redirectTo('archive');
    } else {
        // Пользователь ещё не отправил форму. Показываем форму.
        $results['article'] = new Article();
        require TEMPLATE_PATH . "/editArticle.php";
    }
}
Example #10
0
function Add()
{
    if (!$GLOBALS['authentication']) {
        header("Location: index.php?admin=login");
    }
    $results = array();
    $results['pageTitle'] = "Новая запись";
    $results['formAction'] = "add";
    $results['admin'] = true;
    if (isset($_POST['saveChanges'])) {
        // Пользователь получает форму редактирования статьи: сохраняем новую статью
        $article = new Article();
        $article->storeFormValues($_POST);
        $article->insert();
        //! @todo Проверка в запись БД (Добавить return)
        header("Location: index.php?new=admin&status=changesSaved");
    } elseif (isset($_POST['cancel'])) {
        // Пользователь сбросид результаты редактирования: возвращаемся к списку статей
        header("Location: index.php?new=admin");
    } else {
        // Пользователь еще не получил форму редактирования: выводим форму
        $results['article'] = new Article();
        $results['script'] = "admin/editArticle";
        require $setting["SCRIPT_PATH"] . $setting["TEMPLATE_PATH"] . "/include/page.php";
    }
}