1: <?php
2: 3: 4: 5:
6:
7: if (!defined('XOOPS_ROOT_PATH')) exit();
8:
9: require_once XOOPS_MODULE_PATH . "/user/class/AbstractListAction.class.php";
10: require_once XOOPS_MODULE_PATH . "/user/admin/forms/AvatarFilterForm.class.php";
11: require_once XOOPS_MODULE_PATH . "/user/admin/forms/AvatarListForm.class.php";
12:
13: class User_AvatarListAction extends User_AbstractListAction
14: {
15:
16: var $mAvatarObjects = array();
17: var $mActionForm = null;
18: var $mpageArr = array(5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 60, 70, 80, 90, 100, 0);
19:
20: function prepare(&$controller, &$xoopsUser)
21: {
22: $this->mActionForm =new User_AvatarListForm();
23: $this->mActionForm->prepare();
24: }
25:
26:
27: function &_getHandler()
28: {
29: $handler =& xoops_getmodulehandler('avatar');
30: return $handler;
31: }
32:
33: function &_getPageNavi()
34: {
35: $navi =new XCube_PageNavigator($this->_getBaseUrl(), XCUBE_PAGENAVI_START | XCUBE_PAGENAVI_PERPAGE);
36:
37: $root =& XCube_Root::getSingleton();
38: $perpage = $root->mContext->mRequest->getRequest($navi->mPrefix.'perpage');
39:
40: if (isset($perpage) && intval($perpage) == 0) {
41: $navi->setPerpage(0);
42: }
43: return $navi;
44: }
45:
46: function &_getFilterForm()
47: {
48: $filter =new User_AvatarFilterForm($this->_getPageNavi(), $this->_getHandler());
49: return $filter;
50: }
51:
52: function _getBaseUrl()
53: {
54: return "./index.php?action=AvatarList";
55: }
56:
57: function executeViewIndex(&$controller, &$xoopsUser, &$render)
58: {
59: $render->setTemplateName("avatar_list.html");
60: $render->setAttribute("objects", $this->mObjects);
61: $render->setAttribute("pageNavi", $this->mFilter->mNavi);
62: $render->setAttribute('actionForm', $this->mActionForm);
63: $render->setAttribute('pageArr', $this->mpageArr);
64: $render->setAttribute('filterForm', $this->mFilter);
65:
66: $avt_handler =& $this->_getHandler();
67: $savatar_total = $avt_handler->getCount(new Criteria('avatar_type', 'S'));
68: $cavatar_total = $avt_handler->getCount(new Criteria('avatar_type', 'C'));
69: $render->setAttribute('savatarTotal', $savatar_total);
70: $render->setAttribute('cavatarTotal', $cavatar_total);
71: $render->setAttribute('avatarTotal', $savatar_total+$cavatar_total);
72:
73: }
74:
75: function execute(&$controller, &$xoopsUser)
76: {
77: $form_cancel = $controller->mRoot->mContext->mRequest->getRequest('_form_control_cancel');
78: if ($form_cancel != null) {
79: return USER_FRAME_VIEW_CANCEL;
80: }
81:
82: $this->mActionForm->fetch();
83: $this->mActionForm->validate();
84:
85: if ($this->mActionForm->hasError()) {
86: return $this->_processConfirm($controller, $xoopsUser);
87: }
88: else {
89: return $this->_processSave($controller, $xoopsUser);
90: }
91: }
92:
93: function _processConfirm(&$controller,&$xoopsUser)
94: {
95: $nameArr = $this->mActionForm->get('name');
96: $avatarHandler =& xoops_getmodulehandler('avatar');
97:
98:
99:
100: foreach (array_keys($nameArr) as $aid) {
101: $avatar =& $avatarHandler->get($aid);
102: if (is_object($avatar)) {
103: $this->mAvatarObjects[$aid] =& $avatar;
104: }
105: unset($avatar);
106: }
107:
108: return USER_FRAME_VIEW_INPUT;
109: }
110:
111: function _processSave(&$controller, &$xoopsUser)
112: {
113: $nameArr = $this->mActionForm->get('name');
114: $avatarHandler =& xoops_getmodulehandler('avatar');
115:
116: foreach(array_keys($nameArr) as $aid) {
117: $avatar =& $avatarHandler->get($aid);
118: if (is_object($avatar)) {
119: $olddata['name'] = $avatar->get('avatar_name');
120: $olddata['display'] = $avatar->get('avatar_display');
121: $olddata['weight'] = $avatar->get('avatar_weight');
122: $newdata['name'] = $this->mActionForm->get('name', $aid);
123: $newdata['display'] = $this->mActionForm->get('display', $aid);
124: $newdata['weight'] = $this->mActionForm->get('weight', $aid);
125: if (count(array_diff_assoc($olddata, $newdata)) > 0 ) {
126: $avatar->set('avatar_name', $this->mActionForm->get('name', $aid));
127: $avatar->set('avatar_display', $this->mActionForm->get('display', $aid));
128: $avatar->set('avatar_weight', $this->mActionForm->get('weight', $aid));
129: if (!$avatarHandler->insert($avatar)) {
130: return USER_FRAME_VIEW_ERROR;
131: }
132: }
133: }
134: }
135:
136: $linkHandler =& xoops_getmodulehandler('avatar_user_link');
137:
138: foreach(array_keys($nameArr) as $aid) {
139: if($this->mActionForm->get('delete', $aid) == 1) {
140: $avatar =& $avatarHandler->get($aid);
141: if (is_object($avatar)) {
142: $criteria =new Criteria('avatar_id', $aid);
143: $linkArr =& $linkHandler->getObjects($criteria);
144:
145: if ($avatarHandler->delete($avatar)) {
146: if (count($linkArr) > 0) {
147: $userHandler =& xoops_gethandler('user');
148: foreach ($linkArr as $link) {
149: $user =& $userHandler->get($link->get('user_id'));
150: if (is_object($user)) {
151: $user->set('user_avatar', 'blank.gif');
152: $userHandler->insert($user);
153: }
154: unset($user);
155: }
156: }
157: }
158: else {
159: return USER_FRAME_VIEW_ERROR;
160: }
161: }
162: }
163: }
164: return USER_FRAME_VIEW_SUCCESS;
165:
166: }
167:
168: 169: 170:
171: function executeViewInput(&$controller, &$xoopsUser, &$render)
172: {
173: $render->setTemplateName("avatar_list_confirm.html");
174: $render->setAttribute('avatarObjects', $this->mAvatarObjects);
175: $render->setAttribute('actionForm', $this->mActionForm);
176:
177:
178:
179:
180:
181: $t_arr = $this->mActionForm->get('name');
182: $render->setAttribute('aids', array_keys($t_arr));
183: }
184:
185:
186: function executeViewSuccess(&$controller,&$xoopsUser,&$renderer)
187: {
188: $controller->executeForward('./index.php?action=AvatarList');
189: }
190:
191: function executeViewError(&$controller, &$xoopsUser, &$renderer)
192: {
193: $controller->executeRedirect('./index.php?action=AvatarList', 1, _MD_USER_ERROR_DBUPDATE_FAILED);
194: }
195:
196: function executeViewCancel(&$controller,&$xoopsUser,&$renderer)
197: {
198: $controller->executeForward('./index.php?action=AvatarList');
199: }
200:
201: }
202:
203: ?>
204: