CMS  Version 3.9
edit.inc
Go to the documentation of this file.
1 <?php
2 /**************************************************************
3 
4 Copyright (c) 2014 Sonjara, Inc
5 
6 Permission is hereby granted, free of charge, to any person
7 obtaining a copy of this software and associated documentation
8 files (the "Software"), to deal in the Software without
9 restriction, including without limitation the rights to use,
10 copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the
12 Software is furnished to do so, subject to the following
13 conditions:
14 
15 The above copyright notice and this permission notice shall be
16 included in all copies or substantial portions of the Software.
17 
18 Except as contained in this notice, the name(s) of the above
19 copyright holders shall not be used in advertising or otherwise
20 to promote the sale, use or other dealings in this Software
21 without prior written authorization.
22 
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
25 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
27 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
28 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
30 OTHER DEALINGS IN THE SOFTWARE.
31 
32 *****************************************************************/
33 
34 
35 Fakoli::using("article", "blog", "site", "image", "field_renderers", "taxonomy", "email");
36 Fakoli::usingFile("framework/auto_form.inc");
37 
38 if (!Settings::checkPermission("settings", "editor_roles"))
39 {
40  Fakoli::end("Access Denied");
41 }
42 
43 $article = new Article();
44 $article_id = checkNumeric($_GET["article_id"]);
45 $blog_id = checkNumeric($_GET["blog_id"]);
46 
47 if ($article_id)
48 {
49  $article->load($article_id);
50 }
51 else
52 {
53  $article->created_date = now();
54  $article->publish_date = today();
55 }
56 
57 if ($blog_id)
58 {
59  $blog = new Blog($blog_id);
60  $article->article_type = $blog->title;
61 }
62 
64 $form->getRenderer("message")->height = "160px";
65 
66 $form->ajaxSubmit("function(result) {new ArticleManager().editResult(result);}", "function() {document.id('{$form->id}_error').set('text','Failed to communicate with server'); }");
67 $form->action = "/action/article/edit?article_id={$article_id}";
68 
69 if ($blog_id)
70 {
71  $form->hide("article_type");
72 }
73 
74 $form->hide("sort_order");
75 
76 if(!$article_id || !$article->published)
77 {
78  $form->onSaveComplete = onPublishArticle;
79 }
81 
82 $form->button("Cancel", "new ArticleManager().closeDialog(); return false", null, true);
83 
84 if ($method == "POST")
85 {
86  if ($form->save())
87  {
88  if ($form->deleted)
89  {
90  Fakoli::end("DELETED");
91  }
92  else
93  {
94  Fakoli::end("OK");
95  }
96  }
97 }
98 
99 if ($form->data->article_id)
100 {
101  $title = "Edit Article";
102 }
103 else
104 {
105  $title = "Add Article";
106 
107  if (!$article_id) $form->hide("created_date");
108 }
109 
110 $script .= $form->writeScript();
111 
112 $form->drawForm();
113 
115 {
117 }
118 ?>
if(!Settings::checkPermission("settings", "editor_roles")) $article
Definition: edit.inc:43
onPublishArticle($form)
Definition: edit.inc:114
$blog_id
Definition: edit.inc:45
if($blog_id) $form
Definition: edit.inc:63
$article_id
Definition: edit.inc:44
$script
Definition: edit.inc:110
$blog
Definition: edit.inc:44
Defines the Article class.
Definition: article.inc:45
static buildArticleForm($article)
static onPublishArticle($article)
If an article is marked published but no publish date set (user may wish to set a future publish date...
Definition: blog.inc:41
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition: core.inc:116
static end($message="")
Use this method to terminate execution of a script instead of using the php keywords exit() or die().
Definition: core.inc:1149
static usingFile()
Uses the specified framework file(s) from the framework directory.
Definition: core.inc:369
static checkPermission($component, $name, $account=null)
Check whether a user has a specific permission.
Definition: settings.inc:241
static addTaxonomyFieldRenderers($form, $showSelectAll=true, $group=null, $limitTo=null)
$method
Pull out a simple reference to the request method.
Definition: core.inc:1573