CMS  Version 3.9
role_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("role", "field_renderers");
35 Fakoli::usingFeature("auto_form");
36 Fakoli::assertRole("admin");
37 
38 $menu_item = "Roles";
39 $role_id = checkNumeric($_GET["role_id"]);
40 
41 $role = new SiteRole();
42 
43 $form = new AutoForm($role);
44 $redirect = "/admin/roles";
45 $form->unique("role", "That role has already been defined");
46 $form->annotate("role", "<i>WARNING</i> changes may require code updates.");
47 $form->required("role", "name");
48 $form->annotate("role", "The identifier for the role, used by the application code when determining access to features.");
49 $form->annotate("name", "The display name for the role (shown in forms and tables).");
50 
51 
52 $homePageSelect = new CMSLinkSelectFieldRenderer($form, "home_page", "Home Page");
53 
54 $form->allowDelete = true;
55 $form->onDelete = deleteRole;
56 
57 $form->button("Cancel", $redirect);
58 
59 if ($method == "POST")
60 {
61  if ($form->save())
62  {
63  redirect($redirect);
64  }
65 }
66 
67 if ($role_id)
68 {
69  $role->load($role_id);
70  $title = "Edit User Role: {$role->name}";
71 }
72 else
73 {
74  $title = "Add a New User Role";
75 }
76 
77 $script .= $form->writeScript();
78 
79 $form->drawForm();
80 
81 function deleteRole($role)
82 {
83  ComponentManager::fireEvent("DeleteRole", $role->role);
84  $role->delete();
85  redirect("/admin/roles");
86 }
87 ?>
static fireEvent($event, $parameter=null, $mustBeConsumed=false)
Fire an event to all subscribers as detailed in their manifests.
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 assertRole($role, $redirect="", $message="")
Assert that the user has one of the specified roles.
Definition: core.inc:297
$method
Pull out a simple reference to the request method.
Definition: core.inc:1573
$form
Definition: role_form.inc:43
$role
Definition: role_form.inc:41
$homePageSelect
Definition: role_form.inc:52
$role_id
Definition: role_form.inc:39
$redirect
Definition: role_form.inc:44
$menu_item
Definition: role_form.inc:38
deleteRole($role)
Definition: role_form.inc:81
$script
Definition: role_form.inc:77