source: iPeer/app/controllers/sysparameters_controller.php @ 5d708bf

3.1.xdevhotfixpagodaboxticket463
Last change on this file since 5d708bf was 5d708bf, checked in by Compass <pan.luo@…>, 6 years ago

Add login info header/footer feature

Two new sys parameters are added in order to display some information on
login page. This feature is for satisfying CWL integration.

  • Property mode set to 100644
File size: 5.3 KB
Line 
1<?php
2App::import('Lib', 'neat_string');
3
4/**
5 * SysParametersController
6 *
7 * @uses AppController
8 * @package   CTLT.iPeer
9 * @author    Pan Luo <pan.luo@ubc.ca>
10 * @copyright 2012 All rights reserved.
11 * @license   MIT {@link http://www.opensource.org/licenses/MIT}
12 */
13class SysParametersController extends AppController
14{
15    public $name = 'SysParameters';
16    public $show;
17    public $sortBy;
18    public $direction;
19    public $page;
20    public $order;
21    public $helpers = array('Html', 'Ajax', 'Javascript', 'Time');
22    public $NeatString;
23    public $Sanitize;
24    public $uses = array('SysParameter', 'Personalize');
25    public $components = array('AjaxList');
26
27    /**
28     * __construct
29     *
30     * @access protected
31     * @return void
32     */
33    function __construct()
34    {
35        $this->Sanitize = new Sanitize;
36        $this->NeatString = new NeatString;
37        $this->show = empty($_GET['show'])? 'null': $this->Sanitize->paranoid($_GET['show']);
38        if ($this->show == 'all') {
39            $this->show = 99999999;
40        }
41        $this->sortBy = empty($_GET['sort'])? 'id': $_GET['sort'];
42        $this->direction = empty($_GET['direction'])? 'asc': $this->Sanitize->paranoid($_GET['direction']);
43        $this->page = empty($_GET['page'])? '1': $this->Sanitize->paranoid($_GET['page']);
44        $this->order = $this->sortBy.' '.strtoupper($this->direction);
45        $this->set('title_for_layout', __('Sys Parameters', true));
46        parent::__construct();
47    }
48
49    /**
50     * setUpAjaxList
51     *
52     * @access public
53     * @return void
54     */
55    function setUpAjaxList()
56    {
57        $columns = array(
58            array("SysParameter.id",             __("ID", true),      "3em", "number"),
59            array("SysParameter.parameter_code", __("Code", true),    "15em", "string"),
60            array("SysParameter.parameter_value",__("Value", true),   "auto", "string"),
61            array("SysParameter.parameter_type", __("Type", true),    "6em",   "map",
62            array("I" => "Interger", "B" => "Boolean", "S" => "String")),
63            array("SysParameter.record_status",  __("Status", true),   "5em", "map",
64            array("A" => "Active", "I" => "Inactive")),
65            array("SysParameter.created",        __("Created", true), "10em", "date"),
66            array("SysParameter.modified",       __("Updated", true), "10em", "date"));
67
68        $warning = __("Are you sure you wish to delete this System Parameter?", true);
69
70        $actions = array(
71            array(__("View", true), "", "", "", "view", "SysParameter.id"),
72            array(__("Edit", true), "", "", "", "edit", "SysParameter.id"),
73            array(__("Delete", true), $warning, "", "", "delete", "SysParameter.id"));
74
75        $this->AjaxList->setUp($this->SysParameter, $columns, $actions,
76            "SysParameter.id", "SysParameter.parameter_code");
77    }
78
79    /**
80     * index
81     *
82     * @param string $message
83     *
84     * @access public
85     * @return void
86     */
87    function index()
88    {
89        // Set up the basic static ajax list variables
90        $this->setUpAjaxList();
91        // Set the display list
92        $this->set('paramsForList', $this->AjaxList->getParamsForList());
93    }
94
95    /**
96     * ajaxList
97     *
98     * @access public
99     * @return void
100     */
101    function ajaxList()
102    {
103        // Make sure the present user has permission
104        if (!User::hasPermission('controllers/sysparameters')) {
105            $this->Session->setFlash('You do not have permission to view system parameters', true);
106            $this->redirect('/home');
107        }
108        // Set up the list
109        $this->setUpAjaxList();
110        // Process the request for data
111        $this->AjaxList->asyncGet();
112    }
113
114    /**
115     * view
116     *
117     * @param mixed $id
118     *
119     * @access public
120     * @return void
121     */
122    function view($id)
123    {
124        $this->SysParameter->id = $id;
125        $this->set('data', $this->SysParameter->read());
126    }
127
128    /**
129     * add
130     *
131     * @access public
132     * @return void
133     */
134    function add()
135    {
136        if ($this->SysParameter->save($this->params['data'])) {
137            $this->Session->setFlash(__('The record is saved successfully', true), 'good');
138            $this->redirect('index');
139        } else {
140            $this->Session->setFlash(__('Failed to save the record', true));
141        }
142    }
143
144    /**
145     * edit
146     *
147     * @param bool $id
148     *
149     * @access public
150     * @return void
151     */
152    function edit($id)
153    {
154        if (empty($this->data)) {
155            $this->SysParameter->id = $id;
156            $this->data = $this->SysParameter->read();
157            $this->set('data', $this->data);
158        } else {
159            if ($this->SysParameter->save($this->data)) {
160                $this->Session->setFlash(__('The record is edited successfully.', true), 'good');
161                $this->redirect('index');
162            } else {
163                $this->Session->setFlash($this->SysParameter->errorMessage, true);
164                $this->set('data', $this->data);
165            }
166        }
167    }
168
169    /**
170     * delete
171     *
172     * @param bool $id
173     *
174     * @access public
175     * @return void
176     */
177    function delete($id = null)
178    {
179        if ($this->SysParameter->delete($id)) {
180            $this->Session->setFlash(__('The record is deleted successfully.', true));
181            $this->redirect('index');
182        }
183    }
184}
Note: See TracBrowser for help on using the repository browser.