PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/baser/controllers/user_groups_controller.php

https://github.com/hashing/basercms
PHP | 276 lines | 123 code | 30 blank | 123 comment | 16 complexity | 2b573d90e1277a4027cc36f25f3c3fc7 MD5 | raw file
Possible License(s): MIT
  1. <?php
  2. /* SVN FILE: $Id$ */
  3. /**
  4. * ユーザーグループコントローラー
  5. *
  6. * PHP versions 5
  7. *
  8. * baserCMS : Based Website Development Project <http://basercms.net>
  9. * Copyright 2008 - 2012, baserCMS Users Community <http://sites.google.com/site/baserusers/>
  10. *
  11. * @copyright Copyright 2008 - 2012, baserCMS Users Community
  12. * @link http://basercms.net baserCMS Project
  13. * @package baser.controllers
  14. * @since baserCMS v 0.1.0
  15. * @version $Revision$
  16. * @modifiedby $LastChangedBy$
  17. * @lastmodified $Date$
  18. * @license http://basercms.net/license/index.html
  19. */
  20. /**
  21. * ユーザーグループコントローラー
  22. *
  23. * @package baser.controllers
  24. */
  25. class UserGroupsController extends AppController {
  26. /**
  27. * クラス名
  28. *
  29. * @var string
  30. * @access public
  31. */
  32. var $name = 'UserGroups';
  33. /**
  34. * モデル
  35. *
  36. * @var array
  37. * @access public
  38. */
  39. var $uses = array('UserGroup');
  40. /**
  41. * コンポーネント
  42. *
  43. * @var array
  44. * @access public
  45. */
  46. var $components = array('BcAuth','Cookie','BcAuthConfigure');
  47. /**
  48. * ヘルパ
  49. *
  50. * @var array
  51. * @access public
  52. */
  53. var $helpers = array(BC_TIME_HELPER, BC_FORM_HELPER);
  54. /**
  55. * サブメニューエレメント
  56. *
  57. * @var array
  58. * @access public
  59. */
  60. var $subMenuElements = array('site_configs', 'users', 'user_groups');
  61. /**
  62. * ぱんくずナビ
  63. *
  64. * @var array
  65. * @access public
  66. */
  67. var $crumbs = array(
  68. array('name' => 'ユーザー管理', 'url' => array('controller' => 'users', 'action' => 'index')),
  69. array('name' => 'ユーザーグループ管理', 'url' => array('controller' => 'user_groups', 'action' => 'index'))
  70. );
  71. /**
  72. * beforeFilter
  73. * @return void
  74. * @access public
  75. */
  76. function beforeFilter () {
  77. parent::beforeFilter();
  78. if($this->params['prefix']=='admin'){
  79. $this->set('usePermission',$this->UserGroup->checkOtherAdmins());
  80. }
  81. }
  82. /**
  83. * ユーザーグループの一覧を表示する
  84. *
  85. * @return void
  86. * @access public
  87. */
  88. function admin_index() {
  89. /* データ取得 */
  90. $this->paginate = array('conditions'=>array(),
  91. 'fields'=>array(),
  92. 'order'=>'UserGroup.id',
  93. 'limit'=>10
  94. );
  95. $datas = $this->paginate('UserGroup');
  96. /* 表示設定 */
  97. $this->set('datas',$datas);
  98. $this->pageTitle = 'ユーザーグループ一覧';
  99. $this->help = 'user_groups_index';
  100. }
  101. /**
  102. * [ADMIN] 登録処理
  103. *
  104. * @return void
  105. * @access public
  106. */
  107. function admin_add() {
  108. if($this->data) {
  109. /* 登録処理 */
  110. if(empty($this->data['UserGroup']['auth_prefix'])) {
  111. $this->data['UserGroup']['auth_prefix'] = 'admin';
  112. }
  113. $this->UserGroup->create($this->data);
  114. if($this->UserGroup->save()) {
  115. $message = '新規ユーザーグループ「'.$this->data['UserGroup']['title'].'」を追加しました。';
  116. $this->Session->setFlash($message);
  117. $this->UserGroup->saveDbLog($message);
  118. $this->redirect(array('action' => 'index'));
  119. }else {
  120. $this->Session->setFlash('入力エラーです。内容を修正してください。');
  121. }
  122. }
  123. /* 表示設定 */
  124. $this->pageTitle = '新規ユーザーグループ登録';
  125. $this->help = 'user_groups_form';
  126. $this->render('form');
  127. }
  128. /**
  129. * [ADMIN] 編集処理
  130. *
  131. * @param int ID
  132. * @return void
  133. * @access public
  134. */
  135. function admin_edit($id) {
  136. /* 除外処理 */
  137. if(!$id) {
  138. $this->Session->setFlash('無効なIDです。');
  139. $this->redirect(array('action' => 'index'));
  140. }
  141. if(empty($this->data)) {
  142. $this->data = $this->UserGroup->read(null, $id);
  143. }else {
  144. /* 更新処理 */
  145. if($this->UserGroup->save($this->data)) {
  146. $message = 'ユーザーグループ「'.$this->data['UserGroup']['name'].'」を更新しました。';
  147. $this->Session->setFlash($message);
  148. $this->UserGroup->saveDbLog($message);
  149. $this->redirect(array('action' => 'index', $id));
  150. }else {
  151. $this->Session->setFlash('入力エラーです。内容を修正してください。');
  152. }
  153. }
  154. /* 表示設定 */
  155. $this->pageTitle = 'ユーザーグループ編集:'.$this->data['UserGroup']['title'];
  156. $this->help = 'user_groups_form';
  157. $this->render('form');
  158. }
  159. /**
  160. * [ADMIN] 削除処理 (ajax)
  161. *
  162. * @param int ID
  163. * @return void
  164. * @access public
  165. */
  166. function admin_ajax_delete($id = null) {
  167. /* 除外処理 */
  168. if(!$id) {
  169. $this->ajaxError(500, '無効な処理です。');
  170. }
  171. // メッセージ用にデータを取得
  172. $post = $this->UserGroup->read(null, $id);
  173. /* 削除処理 */
  174. if($this->UserGroup->del($id)) {
  175. $message = 'ユーザーグループ「'.$post['UserGroup']['title'].'」 を削除しました。';
  176. $this->UserGroup->saveDbLog($message);
  177. exit(true);
  178. }
  179. exit();
  180. }
  181. /**
  182. * [ADMIN] 削除処理
  183. *
  184. * @param int ID
  185. * @return void
  186. * @access public
  187. */
  188. function admin_delete($id = null) {
  189. /* 除外処理 */
  190. if(!$id) {
  191. $this->Session->setFlash('無効なIDです。');
  192. $this->redirect(array('action' => 'index'));
  193. }
  194. // メッセージ用にデータを取得
  195. $post = $this->UserGroup->read(null, $id);
  196. /* 削除処理 */
  197. if($this->UserGroup->del($id)) {
  198. $message = 'ユーザーグループ「'.$post['UserGroup']['title'].'」 を削除しました。';
  199. $this->Session->setFlash($message);
  200. $this->UserGroup->saveDbLog($message);
  201. }else {
  202. $this->Session->setFlash('データベース処理中にエラーが発生しました。');
  203. }
  204. $this->redirect(array('action' => 'index'));
  205. }
  206. /**
  207. * [ADMIN] データコピー(AJAX)
  208. *
  209. * @param int $id
  210. * @return void
  211. * @access public
  212. */
  213. function admin_ajax_copy($id) {
  214. if(!$id) {
  215. $this->ajaxError(500, '無効な処理です。');
  216. }
  217. $result = $this->UserGroup->copy($id);
  218. if($result) {
  219. $this->set('data', $result);
  220. } else {
  221. $this->ajaxError(500, $this->UserGroup->validationErrors);
  222. }
  223. }
  224. /**
  225. * ユーザーグループのよく使う項目の初期値を登録する
  226. *
  227. * @return boolean
  228. * @access public
  229. */
  230. function admin_set_default_favorites() {
  231. if(!$this->params['form']) {
  232. $this->ajaxError(500, '無効な処理です。');
  233. }
  234. $user = $this->BcAuth->user();
  235. $this->UserGroup->id = $user['User']['user_group_id'];
  236. $this->UserGroup->recursive = -1;
  237. $data = $this->UserGroup->read();
  238. $data['UserGroup']['default_favorites'] = serialize($this->params['form']);
  239. $this->UserGroup->set($data);
  240. if($this->UserGroup->save()) {
  241. echo true;
  242. }
  243. exit();
  244. }
  245. }
  246. ?>