1: <?php
2:
3: if (!defined('XOOPS_ROOT_PATH')) exit();
4:
5: require_once XOOPS_MODULE_PATH . "/user/class/AbstractListAction.class.php";
6: require_once XOOPS_MODULE_PATH . "/user/admin/forms/RanksFilterForm.class.php";
7: require_once XOOPS_MODULE_PATH . "/user/admin/forms/RanksListForm.class.php";
8:
9: class User_RanksListAction extends User_AbstractListAction
10: {
11: var $mRanksObjects = array();
12: var $mActionForm = null;
13: var $mpageArr = array(5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 60, 70, 80, 90, 100, 0);
14:
15: function prepare(&$controller, &$xoopsUser)
16: {
17: $this->mActionForm =new User_RanksListForm();
18: $this->mActionForm->prepare();
19: }
20:
21: function &_getHandler()
22: {
23: $handler =& xoops_getmodulehandler('ranks');
24: return $handler;
25: }
26:
27: function &_getPageNavi()
28: {
29: $navi =new XCube_PageNavigator($this->_getBaseUrl(), XCUBE_PAGENAVI_START | XCUBE_PAGENAVI_PERPAGE);
30:
31: $root =& XCube_Root::getSingleton();
32: $perpage = $root->mContext->mRequest->getRequest($navi->mPrefix.'perpage');
33:
34: if (isset($perpage) && intval($perpage) == 0) {
35: $navi->setPerpage(0);
36: }
37: return $navi;
38: }
39:
40: function &_getFilterForm()
41: {
42: $filter =new User_RanksFilterForm($this->_getPageNavi(), $this->_getHandler());
43: return $filter;
44: }
45:
46: function _getBaseUrl()
47: {
48: return "./index.php?action=RanksList";
49: }
50:
51: function executeViewIndex(&$controller, &$xoopsUser, &$render)
52: {
53: $render->setTemplateName("ranks_list.html");
54: $render->setAttribute("objects", $this->mObjects);
55: $render->setAttribute("pageNavi", $this->mFilter->mNavi);
56: $render->setAttribute('actionForm', $this->mActionForm);
57: $render->setAttribute('pageArr', $this->mpageArr);
58: $render->setAttribute('filterForm', $this->mFilter);
59: $rank_handler =& $this->_getHandler();
60: $rank_total = $rank_handler->getCount();
61: $rank_s_total = $rank_handler->getCount(new Criteria('rank_special', 1));
62: $render->setAttribute('rankTotal_S', $rank_s_total);
63: $render->setAttribute('rankTotal', $rank_total);
64:
65: }
66:
67: function execute(&$controller, &$xoopsUser)
68: {
69: $form_cancel = $controller->mRoot->mContext->mRequest->getRequest('_form_control_cancel');
70: if ($form_cancel != null) {
71: return USER_FRAME_VIEW_CANCEL;
72: }
73:
74: $this->mActionForm->fetch();
75: $this->mActionForm->validate();
76:
77: if ($this->mActionForm->hasError()) {
78: return $this->_processConfirm($controller, $xoopsUser);
79: }
80: else {
81: return $this->_processSave($controller, $xoopsUser);
82: }
83: }
84:
85: function _processConfirm(&$controller,&$xoopsUser)
86: {
87: $titleArr = $this->mActionForm->get('title');
88: $ranksHandler =& xoops_getmodulehandler('ranks');
89:
90:
91:
92: foreach (array_keys($titleArr) as $rid) {
93: $ranks =& $ranksHandler->get($rid);
94: if (is_object($ranks)) {
95: $this->mRanksObjects[$rid] =& $ranks;
96: }
97: unset($ranks);
98: }
99:
100: return USER_FRAME_VIEW_INPUT;
101: }
102:
103: function _processSave(&$controller, &$xoopsUser)
104: {
105: $titleArr = $this->mActionForm->get('title');
106: $ranksHandler =& xoops_getmodulehandler('ranks');
107:
108: foreach(array_keys($titleArr) as $rid) {
109: $ranks =& $ranksHandler->get($rid);
110: if (is_object($ranks)) {
111: $olddata['title'] = $ranks->get('rank_title');
112: $olddata['min'] = $ranks->get('rank_min');
113: $olddata['max'] = $ranks->get('rank_max');
114: $newdata['title'] = $this->mActionForm->get('title', $rid);
115: $newdata['min'] = $this->mActionForm->get('min', $rid);
116: $newdata['max'] = $this->mActionForm->get('max', $rid);
117: if (count(array_diff_assoc($olddata, $newdata)) > 0 ) {
118: $ranks->set('rank_title', $this->mActionForm->get('title', $rid));
119: $ranks->set('rank_min', $this->mActionForm->get('min', $rid));
120: $ranks->set('rank_max', $this->mActionForm->get('max', $rid));
121: if (!$ranksHandler->insert($ranks)) {
122: return USER_FRAME_VIEW_ERROR;
123: }
124: }
125: }
126: }
127:
128: foreach(array_keys($titleArr) as $rid) {
129: if($this->mActionForm->get('delete', $rid) == 1) {
130: $ranks =& $ranksHandler->get($rid);
131: if (is_object($ranks)) {
132: if ( !$ranksHandler->delete($ranks) ) {
133: return USER_FRAME_VIEW_ERROR;
134: }
135: }
136: }
137: }
138: return USER_FRAME_VIEW_SUCCESS;
139:
140: }
141:
142: 143: 144:
145: function executeViewInput(&$controller, &$xoopsUser, &$render)
146: {
147: $render->setTemplateName("ranks_list_confirm.html");
148: $render->setAttribute('ranksObjects', $this->mRanksObjects);
149: $render->setAttribute('actionForm', $this->mActionForm);
150:
151:
152:
153:
154:
155: $t_arr = $this->mActionForm->get('title');
156: $render->setAttribute('rids', array_keys($t_arr));
157: }
158:
159:
160: function executeViewSuccess(&$controller,&$xoopsUser,&$renderer)
161: {
162: $controller->executeForward('./index.php?action=RanksList');
163: }
164:
165: function executeViewError(&$controller, &$xoopsUser, &$renderer)
166: {
167: $controller->executeRedirect('./index.php?action=RanksList', 1, _MD_USER_ERROR_DBUPDATE_FAILED);
168: }
169:
170: function executeViewCancel(&$controller,&$xoopsUser,&$renderer)
171: {
172: $controller->executeForward('./index.php?action=RanksList');
173: }
174:
175:
176: }
177:
178: ?>
179: