示例#1
0
 public function action_multiple()
 {
     $ids = \Input::post('id');
     $act = trim(\Input::post('act'));
     $redirect = $this->getAndSetSubmitRedirection();
     if (\Extension\NoCsrf::check()) {
         // if action is delete.
         if ($act == 'del') {
             // check permission.
             if (\Model_AccountLevelPermission::checkAdminPermission('account_perm', 'account_delete_perm') == false) {
                 \Response::redirect($redirect);
             }
             if (is_array($ids)) {
                 foreach ($ids as $id) {
                     // get target level group id
                     $lvls = \DB::select()->as_object()->from(\Model_AccountLevel::getTableName())->where('account_id', $id)->execute();
                     // not found
                     if (count($lvls) <= 0) {
                         continue;
                     } else {
                         // format level group for check can i add, edit
                         $level_group = array();
                         foreach ($lvls as $lvl) {
                             $level_group[] = $lvl->level_group_id;
                         }
                     }
                     if (\Model_Accounts::forge()->canIAddEditAccount($level_group) == true) {
                         // delete account.
                         \Model_Accounts::deleteAccount($id);
                         // clear cache
                         \Extension\Cache::deleteCache('model.accounts-checkAccount-' . \Model_Sites::getSiteId() . '-' . $id);
                     }
                 }
             }
         } elseif ($act == 'enable') {
             // check permission.
             if (\Model_AccountLevelPermission::checkAdminPermission('account_perm', 'account_delete_perm') == false) {
                 \Response::redirect($redirect);
             }
             if (is_array($ids)) {
                 foreach ($ids as $id) {
                     if ($id == '0') {
                         continue;
                     }
                     // get target level group id
                     $lvls = \DB::select()->as_object()->from(\Model_AccountLevel::getTableName())->where('account_id', $id)->execute();
                     // not found
                     if (count($lvls) <= 0) {
                         continue;
                     } else {
                         // format level group for check can i add, edit
                         $level_group = array();
                         foreach ($lvls as $lvl) {
                             $level_group[] = $lvl->level_group_id;
                         }
                     }
                     if (\Model_Accounts::forge()->canIAddEditAccount($level_group) == true) {
                         \DB::update(\Model_Accounts::getTableName())->where('account_id', $id)->set(['account_status' => '1', 'account_status_text' => null])->execute();
                         unset($entry);
                     }
                     // clear cache
                     \Extension\Cache::deleteCache('model.accounts-checkAccount-' . \Model_Sites::getSiteId() . '-' . $id);
                 }
             }
         } elseif ($act == 'disable') {
             // check permission.
             if (\Model_AccountLevelPermission::checkAdminPermission('account_perm', 'account_delete_perm') == false) {
                 \Response::redirect($redirect);
             }
             if (is_array($ids)) {
                 foreach ($ids as $id) {
                     if ($id == '0') {
                         continue;
                     }
                     // get target level group id
                     $lvls = \DB::select()->as_object()->from(\Model_AccountLevel::getTableName())->where('account_id', $id)->execute();
                     // not found
                     if (count($lvls) <= 0) {
                         continue;
                     } else {
                         // format level group for check can i add, edit
                         $level_group = array();
                         foreach ($lvls as $lvl) {
                             $level_group[] = $lvl->level_group_id;
                         }
                     }
                     if (\Model_Accounts::forge()->canIAddEditAccount($level_group) == true) {
                         \DB::update(\Model_Accounts::getTableName())->where('account_id', $id)->set(['account_status' => '0', 'account_status_text' => null])->execute();
                     }
                     // clear cache
                     \Extension\Cache::deleteCache('model.accounts-checkAccount-' . \Model_Sites::getSiteId() . '-' . $id);
                 }
             }
         }
     }
     // go back
     \Response::redirect($redirect);
 }