CMS  Version 3.9
scroll_part_dialog.inc
Go to the documentation of this file.
1 <?php
2 Fakoli::using("scroll", "field_renderers");
3 
4 if (!Settings::checkPermission("settings", "editor_roles"))
5 {
6  Fakoli::end("Access Denied");
7 }
8 
9 $scroll_id = checkNumeric($_GET["scroll_id"]);
10 $scroll_part_id = checkNumeric($_GET["scroll_part_id"]);
11 $content_type = checkIdentifier($_GET["content_type"]);
12 
13 if ($scroll_part_id)
14 {
15  $part = new ScrollPart($scroll_part_id);
16  if ($scroll_id != $part->scroll_id)
17  {
18  throw new FakoliException("Parameter Mismatch");
19  }
20 }
21 else
22 {
23  if (!$scroll_id)
24  {
25  throw new FakoliException("Scroll Mismatch");
26  }
27 
28  if ($content_type != 'HTML' && $content_type != 'Code')
29  {
30  throw new Exception("Invalid Content Type");
31  }
32 
33  $part = new ScrollPart();
34  $part->scroll_id = $scroll_id;
35  $part->content_type = $content_type;
36 }
37 
38 $form = new AutoForm($part, "POST", "/action/scroll/scroll_part_dialog?scroll_id={$scroll_id}&scroll_part_id={$scroll_part_id}&content_type={$content_type}");
39 $form->ajaxSubmit("function(response) { ScrollPartManager.editPartResponse(response); }");
40 $form->allowDelete = true;
41 $form->alias("css_class", "CSS Class");
42 $form->hide("content_type", "scroll_id", "sort_order");
43 
45 
46 $form->onInsertPreProcess = function($form)
47 {
48  $form->data->sort_order = Query::create(ScrollPart, "WHERE scroll_id=:s")
49  ->bind(":s", $form->data->scroll_id)
50  ->executeValue("MAX(sort_order) + 1");
51 };
52 
53 if ($part->content_type == "HTML")
54 {
55  $form->hide("php_code_file");
56 }
57 else
58 {
59  $form->hide("content");
60  $codeSelect = new CodeFileSelectFieldRenderer($form, "php_code_file", "PHP Code File", "modules");
61 }
62 
63 if ($method == "POST")
64 {
65  if ($form->save())
66  {
67  Fakoli::end("OK");
68  }
69  else
70  {
71  Fakoli::end($form->msg);
72  }
73 }
74 
75 $script .= $form->writeScript();
76 $form->drawForm();
FakoliException is the base exception class for all Fakoli errors.
Definition: core.inc:53
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 checkPermission($component, $name, $account=null)
Check whether a user has a specific permission.
Definition: settings.inc:241
$method
Pull out a simple reference to the request method.
Definition: core.inc:1573
$scroll_part_id
if(!Settings::checkPermission("settings", "editor_roles")) $scroll_id
if($method=="POST") $script