CMS  Version 3.9
help_page_form.inc
Go to the documentation of this file.
1 <?php
2 /**************************************************************
3 
4  Copyright (c) 2010 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 Fakoli::using("online_help");
35 Fakoli::usingFeature("auto_form", "tab_bar", "data_view");
36 
37 $menu_item = "Online Help";
38 
39 $help_book_id = checkNumeric($_GET["help_book_id"]);
40 if (!$help_book_id) redirect("help_books");
41 
42 $help_page_id = checkNumeric($_GET["help_page_id"]);
43 $parent_id = checkNumeric($_GET["parent_id"]);
44 
46 $title = "Help Page for {$helpBook->title}";
47 
49 $subpage = array();
50 
51 if ($help_page_id)
52 {
53  $helpPage->load($help_page_id);
54  $title = "Edit Help Page Details for {$helpPage->title}";
55  $subpages = $helpPage->Children();
56 }
57 else
58 {
59  if($parent_id)
60  {
61  $helpPage->parent_id = $parent_id;
62  }
63  $helpPage->sort_order = Query::create(HelpPage, "WHERE help_book_id=:help_book_id")
64  ->bind(":help_book_id", $help_book_id)
65  ->executeValue("MAX(sort_order)") + 1;
66  $helpPage->help_book_id = $help_book_id;
67  $title = "Add a new Help Page";
68 }
69 
70 
71 $form = new AutoForm($helpPage);
72 $form->required("title", "identifier");
73 $form->hide("help_book_id", "sort_order");
74 
75 $form->allowDelete = count($subpages) ? false : true;
76 
77 if($help_page_id && !count($subpages))
78 {
79  $form->button("Add a Subpage", "help_page_form?help_book_id=$help_book_id&parent_id=$help_page_id");
80 }
81 
82 $parentSelect = new SelectFieldRenderer($form, "parent_id", "Parent Page", OnlineHelpHelper::formatParentOptions($helpBook, $helpPage));
83 
84 $form->layout = new UngroupedFormLayout($form);
85 $form->group("all", "title", "identifier", "parent_id");
86 
87 $form->button("Cancel", $redirect);
88 
90 $table->emptyMessage = "There are no subpages.";
91 
92 
93 if ($method == "POST")
94 {
95  if ($form->save())
96  {
97  redirect("help_pages?help_book_id={$help_book_id}");
98  }
99 }
100 
101 
103 $tabs->page = "/admin/help_pages";
104 
105 $script = $form->writeScript();
106 $script .= $table->writeScript();
107 
108 $tabs->writeHTML();
109 ?>
110 <div id="tab_border">
111 <?
112 $form->drawForm();
113 
114 if(count($subpages))
115 {
116  echo "<h3>Subpages</h3>\n";
117  $table->drawView();
118  echo "<p><a class='button' href='help_page_form?help_book_id=$help_book_id&parent_id=$help_page_id'>Add a Subpage</a></p>\n";
119 }
120 ?>
121 </div>
$redirect
return false
static usingFeature()
Uses the specified framework feature(s).
Definition: core.inc:388
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition: core.inc:116
static buildPageTable($pages, $help_book_id)
static formatParentOptions($helpBook, $helpPage)
$method
Pull out a simple reference to the request method.
Definition: core.inc:1573
$parent_id
$helpBook
$helpPage
$help_book_id
$subpage
if($method=="POST") $tabs
$menu_item
$help_page_id
if($help_page_id &&!count($subpages)) $parentSelect
$title
$table
$subpages