source: iPeer/app/controllers/sysparameters_controller.php @ f1f2981

3.1.xdevhotfixpagodaboxticket463
Last change on this file since f1f2981 was f1f2981, checked in by Michael Tang <michael.tang@…>, 6 years ago

removed unused views and edited some permission checking

I've removed index.ctp and search.ctp for evaluations because they
are no longer being used.

In the evaluation controller, I have started to edit the permission
checking mechanism. Before the function "noStudentsAllow" was used
to prevent student users to access those sections of the
application. I have changed some of them to hasPermission.

For evaluations/export, I have also checked whether the user is an
instructor or admin of the course. For some other functions such
as sys_parameters and sys_functions, only superadmins can access
them, because currently it is the only role that has the permission
for those controllers.

  • Property mode set to 100644
File size: 5.8 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($message='')
88    {
89        // Make sure the present user has permission
90        if (!User::hasPermission('controllers/sysparameters')) {
91            $this->Session->setFlash('You do not have permission to view system parameters', true);
92            $this->redirect('/home');
93        }
94        // Set the top message
95        $this->set('message', $message);
96        // Set up the basic static ajax list variables
97        $this->setUpAjaxList();
98        // Set the display list
99        $this->set('paramsForList', $this->AjaxList->getParamsForList());
100    }
101
102    /**
103     * ajaxList
104     *
105     * @access public
106     * @return void
107     */
108    function ajaxList()
109    {
110        // Make sure the present user has permission
111        if (!User::hasPermission('controllers/sysparameters')) {
112            $this->Session->setFlash('You do not have permission to view system parameters', true);
113            $this->redirect('/home');
114        }
115        // Set up the list
116        $this->setUpAjaxList();
117        // Process the request for data
118        $this->AjaxList->asyncGet();
119    }
120
121    /**
122     * view
123     *
124     * @param mixed $id
125     *
126     * @access public
127     * @return void
128     */
129    function view($id)
130    {
131        $this->SysParameter->id = $id;
132        $this->set('data', $this->SysParameter->read());
133    }
134
135    /**
136     * add
137     *
138     * @access public
139     * @return void
140     */
141    function add()
142    {
143        if (empty($this->data)) {
144            $this->render();
145        } else {
146            if ($this->SysParameter->save($this->params['data'])) {
147                $message = __('The record is saved successfully', true);
148                $this->redirect('sysparameters/index/'.$message);
149            } else {
150                $this->set('data', $this->data);
151                $this->render('edit');
152            }
153        }
154    }
155
156    /**
157     * edit
158     *
159     * @param bool $id
160     *
161     * @access public
162     * @return void
163     */
164    function edit($id=null)
165    {
166        if (empty($this->data)) {
167            $this->SysParameter->id = $id;
168            $this->data = $this->SysParameter->read();
169            $this->set('data', $this->data);
170            $this->render();
171        } else {
172            if ($this->SysParameter->save($this->data)) {
173                $this->Session->setFlash(__('The record is edited successfully.', true));
174                $this->redirect('index');
175            } else {
176                $this->Session->setFlash($this->SysParameter->errorMessage, true);
177                $this->set('data', $this->data);
178                $this->render();
179            }
180        }
181    }
182
183    /**
184     * delete
185     *
186     * @param bool $id
187     *
188     * @access public
189     * @return void
190     */
191    function delete($id = null)
192    {
193        if ($this->SysParameter->delete($id)) {
194            $this->Session->setFlash(__('The record is deleted successfully.', true));
195            $this->redirect('index');
196        }
197    }
198}
Note: See TracBrowser for help on using the repository browser.