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: class MassRemoveFromList extends MassAction {
38:
39: protected $_label;
40:
41: /**
42: * Renders the mass action dialog, if applicable
43: * @param string $gridId id of grid view
44: */
45: public function renderDialog ($gridId, $modelName) {
46: echo "
47: <div class='mass-action-dialog' id='".$this->getDialogId ($gridId)."'
48: style='display: none;'>
49: <span>".
50: Yii::t('app', 'Remove all selected records from this list?')."
51: </span>
52: </div>";
53: }
54:
55: /**
56: * @return string label to display in the dropdown list
57: */
58: public function getLabel () {
59: if (!isset ($this->_label)) {
60: $this->_label = Yii::t('app', 'Remove selected from list');
61: }
62: return $this->_label;
63: }
64:
65: public function getPackages () {
66: return array_merge (parent::getPackages (), array (
67: 'X2MassRemoveFromList' => array(
68: 'baseUrl' => Yii::app()->request->baseUrl,
69: 'js' => array(
70: 'js/X2GridView/MassRemoveFromList.js',
71: ),
72: 'depends' => array ('X2MassAction'),
73: ),
74: ));
75: }
76:
77: public function execute (array $gvSelection) {
78: if (Yii::app()->controller->modelClass !== 'Contacts' || !isset ($_POST['listId'])) {
79: throw new CHttpException (400, Yii::t('app', 'Bad Request'));
80: }
81: $listId = $_POST['listId'];
82:
83: foreach($gvSelection as $contactId) {
84: if(!ctype_digit((string) $contactId)) {
85: throw new CHttpException (400, Yii::t('app', 'Bad Request'));
86: }
87: }
88:
89: $list = CActiveRecord::model('X2List')->findByPk($listId);
90: $updatedRecordsNum = sizeof ($gvSelection);
91: $success = true;
92:
93: // check permissions
94: if($list !== null && Yii::app()->controller->checkPermissions($list, 'edit')) {
95: if ($list->removeIds($gvSelection)) {
96: self::$successFlashes[] = Yii::t(
97: 'app', '{updatedRecordsNum} record'.($updatedRecordsNum === 1 ? '' : 's').
98: ' removed from list "{list}"', array (
99: '{updatedRecordsNum}' => $updatedRecordsNum,
100: '{list}' => $list->name,
101: )
102: );
103: } else {
104: $success = false;
105: self::$errorFlashes[] = Yii::t(
106: 'app', 'The selected record'.($updatedRecordsNum === 1 ? '' : 's').
107: ' could not be removed from this list');
108: }
109: } else {
110: $success = false;
111: self::$errorFlashes[] = Yii::t(
112: 'app', 'You do not have permission to modify this list');
113: }
114:
115: return $success ? $updatedRecordsNum : 0;
116: }
117:
118: }
119: