Це просто код

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
class adminGroups extends UI_Base {
public $action = "actionViewAll";
public $template = "adminGroups.html";
public $group_id = NULL;
/**
* @desc constructor
* @access public
* @param
* @return
*/
public function adminGroups(&$user)
{
UI_Base::UI_Base($user);
if ($this->user->SU_getProperty("USER_TYPE") != 'A') $this->setRedirect("StaticPage", array("PAGE"=>"engineAccessDenied.html"));
$this->group_id = (int)$_REQUEST["GROUP_ID"];
switch ($_REQUEST["todo"]) {
case "new":
case "edit": $this->setAction("actionEditGroup"); break;
case "delete": $this->setAction("actionDeleteGroup"); break;
case "success": $this->setAction("actionSuccess"); break;
}
if (!empty($_REQUEST["edit_group_submit"])) {
$this->setAction("actionUpdateGroup");
}
}
/**
* @desc view all groups
* @access public
* @param
* @return
*/
public function actionViewAll()
{
$this->addOutputVar(selectVector("SELECT * from USER_GROUPS"), "GROUPS_LIST");
}
/**
* @desc edit group
* @access public
* @param
* @return
*/
public function actionEditGroup()
{
$this->_actionPrepareGroupForm();
if (!empty($this->group_id)) {
$query = "SELECT * from USER_GROUPS where GROUP_ID=".$this->group_id;
$this->form->updateForm(selectHashTable($query), "VAL_");
}
$this->addOutputVar($this->form->outputForm(false));
}
/**
* @desc update group info
* @access public
* @param
* @return
*/
public function actionUpdateGroup()
{
$this->_actionPrepareGroupForm();
$this->form->updateFormFiltered($_POST, "gpcStripslashes");
if ($this->form->validateForm()) {
// add / update complete
$group_info = $this->form->getFieldsWithPrefix("VAL_");
if (empty($group_info["GROUP_ID"])) {
$query = setInsertValues($group_info, "USER_GROUPS");
} else {
$query = setUpdateQuery($group_info, "USER_GROUPS", "GROUP_ID=".$group_info["GROUP_ID"]);
}
queryExecute($query);
$this->sessionMessenger->sendMessage(array("message" => "Operation complete"));
$this->setSelfRedirect(array("todo" => "success"));
} else {
// form validation error
$this->run("actionEditPage");
}
}
/**
* @desc delete group and all associations with users
* @access public
* @param
* @return
*/
public function actionDeleteGroup()
{
if (!empty($this->group_id)) {
queryExecute("DELETE from USER_GROUPS where GROUP_ID=".$this->group_id);
queryExecute("DELETE from USER_TO_GROUP where GROUP_ID=".$this->group_id);
$this->sessionMessenger->sendMessage(array("message" => "Operation complete"));
$this->setSelfRedirect(array("todo" => "success"));
}
$this->run("actionViewAll");
}
/**
* @desc output success message
* @access public
* @param
* @return
*/
public function actionSuccess()
{
$message = $this->sessionMessenger->getMessage();
$this->addOutputVar($message["message"], "MESSAGE");
}
/**
* @desc this function called before interface run
* @access public
* @param
* @return boolean true or redirect to access denied page
*/
public function checkAccess()
{
if (!$this->user->SU_isUserInGroup('SITE ADMINISTRATORS')) $this->setRedirect("StaticPage", array("PAGE"=>"engineAccessDenied.html"));
return true;
}
/**
* @desc prepare group form for this interface ($this->form)
* @access private
* @return
*/
public function _actionPrepareGroupForm()
{
if (empty($this->form)) {
$this->form = new Form("edit_group", "", engine_TEMPLATES_PATH."forms/adminGroup.xml");
$this->form->setAttribute("action", "index.php");
}
}
// end of class adminGroups
}
?>