1: <?php
2: /*****************************************************************************************
3: * X2Engine Open Source Edition is a customer relationship management program developed by
4: * X2Engine, Inc. Copyright (C) 2011-2016 X2Engine Inc.
5: *
6: * This program is free software; you can redistribute it and/or modify it under
7: * the terms of the GNU Affero General Public License version 3 as published by the
8: * Free Software Foundation with the addition of the following permission added
9: * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10: * IN WHICH THE COPYRIGHT IS OWNED BY X2ENGINE, X2ENGINE DISCLAIMS THE WARRANTY
11: * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12: *
13: * This program is distributed in the hope that it will be useful, but WITHOUT
14: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15: * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16: * details.
17: *
18: * You should have received a copy of the GNU Affero General Public License along with
19: * this program; if not, see http://www.gnu.org/licenses or write to the Free
20: * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21: * 02110-1301 USA.
22: *
23: * You can contact X2Engine, Inc. P.O. Box 66752, Scotts Valley,
24: * California 95067, USA. or at email address contact@x2engine.com.
25: *
26: * The interactive user interfaces in modified source and object code versions
27: * of this program must display Appropriate Legal Notices, as required under
28: * Section 5 of the GNU Affero General Public License version 3.
29: *
30: * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31: * these Appropriate Legal Notices must retain the display of the "Powered by
32: * X2Engine" logo. If the display of the logo is not reasonably feasible for
33: * technical reasons, the Appropriate Legal Notices must display the words
34: * "Powered by X2Engine".
35: *****************************************************************************************/
36:
37: Yii::import('application.components.X2GridView.massActions.*');
38:
39: class X2GridViewMassActionAction extends CAction {
40:
41: /**
42: * Mass action names and mass action class names
43: */
44: private $massActionClasses = array (
45: 'MassAddToList',
46: 'MassCompleteAction',
47: 'MassRemoveFromList',
48: 'MassUncompleteAction',
49: 'NewListFromSelection',
50: 'MassMoveFileSysObjToFolder',
51: 'MassRenameFileSysObj',
52:
53: );
54:
55: private $_massActions;
56:
57: /**
58: * @return array instances of mass action objects indexed by mass action name
59: */
60: public function getMassActionInstances () {
61: if (!isset ($this->_massActions)) {
62: $this->_massActions = array ();
63: foreach ($this->massActionClasses as $class) {
64: $this->_massActions[$class] = new $class;
65: }
66: }
67: return $this->_massActions;
68: }
69:
70: /**
71: * Execute specified mass action on specified records
72: */
73: public function run(){
74: if (Yii::app()->user->isGuest) {
75: Yii::app()->controller->redirect(Yii::app()->controller->createUrl('/site/login'));
76: }
77:
78: if (Yii::app()->request->getRequestType () === 'GET') {
79: $_POST = $_GET;
80: }
81:
82: if (isset ($_POST['passConfirm']) && $_POST['passConfirm']) {
83: MassAction::superMassActionPasswordConfirmation ();
84: return;
85: }
86: if (!isset ($_POST['massAction']) ||
87: ((!isset ($_POST['superCheckAll']) || !$_POST['superCheckAll']) &&
88: (!isset ($_POST['gvSelection']) || !is_array ($_POST['gvSelection'])))) {
89:
90: /**/AuxLib::debugLogR ('run error');
91: throw new CHttpException (400, Yii::t('app', 'Bad Request'));
92: }
93: $massAction = $_POST['massAction'];
94: $massActionInstance = $this->getInstanceFor ($massAction);
95:
96: if (isset ($_POST['superCheckAll']) && $_POST['superCheckAll']) {
97: $uid = $_POST['uid'];
98: $idChecksum = $_POST['idChecksum'];
99: $totalItemCount = intval ($_POST['totalItemCount']);
100: $massActionInstance->superExecute ($uid, $totalItemCount, $idChecksum);
101: } else {
102: $gvSelection = $_POST['gvSelection'];
103: if ($massActionInstance->beforeExecute ()) {
104: $massActionInstance->execute ($gvSelection);
105: }
106: $massActionInstance::echoResponse ();
107: }
108: }
109:
110: /**
111: * validates mass action name and returns MassAction instance that corresponds with it
112: * @param string $massAction
113: */
114: private function getInstanceFor ($massAction) {
115: $instances = $this->getMassActionInstances ();
116: if (!in_array ($massAction, array_keys ($instances))) {
117: /**/AuxLib::debugLogR ('invalid mass action '.$massAction);
118: throw new CHttpException (400, Yii::t('app', 'Bad Request'));
119: }
120: return $instances[$massAction];
121: }
122:
123: }
124:
125: ?>
126: