<commit_before><?php
namespace Admin\Controller;

use App\Auth\BarCodeAuthenticate;
use App\Lib\Error\Exception\InvalidParameterException;
use App\Mailer\AppEmail;
use Cake\Auth\DefaultPasswordHasher;
use Cake\Core\Configure;
use Cake\Core\Exception\Exception;
use Cake\Datasource\Exception\RecordNotFoundException;
use Cake\Http\Exception\NotFoundException;
use Cake\ORM\TableRegistry;
use Cake\Http\Exception\ForbiddenException;

/**
 * CustomersController
 *
 * FoodCoopShop - The open source software for your foodcoop
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @since         FoodCoopShop 1.0.0
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
 * @author        <NAME> <<EMAIL>>
 * @copyright     Copyright (c) <NAME>, https://www.rothauer-it.com
 * @link          https://www.foodcoopshop.com
 */

class CustomersController extends AdminAppController
{

    public function isAuthorized($user)
    {
        switch ($this->getRequest()->getParam('action')) {
            case 'generateMemberCards':
                return Configure::read('appDb.FCS_SELF_SERVICE_MODE_FOR_STOCK_PRODUCTS_ENABLED') && ($this->AppAuth->isSuperadmin() || $this->AppAuth->isAdmin());
                break;
            case 'generateMyMemberCard':
                return Configure::read('appDb.FCS_SELF_SERVICE_MODE_FOR_STOCK_PRODUCTS_ENABLED') && ($this->AppAuth->isSuperadmin() || $this->AppAuth->isAdmin() || $this->AppAuth->isCustomer());
                break;
            case 'edit':
            case 'creditBalanceSum':
                return $this->AppAuth->isSuperadmin();
                break;
            case 'profile':
                return $this->AppAuth->isSuperadmin() || $this->AppAuth->isAdmin() || $this->AppAuth->isCustomer();
                break;
            case 'delete':
                return $this->AppAuth->isSuperadmin();
                break;
            case 'changePassword':
                return $this->AppAuth->user();
                break;
            default:
                return $this->AppAuth->isSuperadmin() || $this->AppAuth->isAdmin();
                break;
        }
    }
    
    public function generateMyMemberCard()
    {
        $customerId = $this->AppAuth->getUserId();
        $this->prepareGenerateMemberCards($customerId);
    }
    
    public function generateMemberCards()
    {
        $customerIds = $this->getRequest()->getQuery('customerIds');
        $customerIds = explode(',', $customerIds);
        $this->prepareGenerateMemberCards($customerIds);
    }
    
    private function prepareGenerateMemberCards($customerIds)
    {
        if (empty($customerIds)) {
            throw new InvalidParameterException('no customer id passed');
        }
        
        $this->Customer = TableRegistry::getTableLocator()->get('Customers');
        $this->Customer->dropManufacturersInNextFind();
        $customers = $this->Customer->find('all', [
            'fields' => [
                'bar_code' => BarCodeAuthenticate::getIdentifierField($this->Customer)
            ],
            'conditions' => [
                'Customers.id_customer IN' => $customerIds
            ],
            'order' => [
                'Customers.' . Configure::read('app.customerMainNamePart') => 'ASC'
            ],
            'contain' => [
                'AddressCustomers', // to make exclude happen using dropManufacturersInNextFind
            ]
        ]);
        $customers->select($this->Customer);
        $customers->select($this->Customer->AddressCustomers);
        $this->set('customers', $customers);
    }

    public function ajaxEditGroup()
    {
        $customerId = (int) $this->getRequest()->getData('customerId');
        $groupId = (int) $this->getRequest()->getData('groupId');

        if (! in_array($groupId, array_keys(Configure::read('app.htmlHelper')->getAuthDependentGroups($this->AppAuth->getGroupId())))) {<commit_msg>removed static access<commit_after><?php
namespace Admin\Controller;

use App\Auth\BarCodeAuthenticate;
use App\Lib\Error\Exception\InvalidParameterException;
use App\Mailer\AppEmail;
use Cake\Auth\DefaultPasswordHasher;
use Cake\Core\Configure;
use Cake\Core\Exception\Exception;
use Cake\Datasource\Exception\RecordNotFoundException;
use Cake\Http\Exception\NotFoundException;
use Cake\ORM\TableRegistry;
use Cake\Http\Exception\ForbiddenException;

/**
 * CustomersController
 *
 * FoodCoopShop - The open source software for your foodcoop
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @since         FoodCoopShop 1.0.0
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
 * @author        <NAME> <<EMAIL>>
 * @copyright     Copyright (c) <NAME>, https://www.rothauer-it.com
 * @link          https://www.foodcoopshop.com
 */

class CustomersController extends AdminAppController
{

    public function isAuthorized($user)
    {
        switch ($this->getRequest()->getParam('action')) {
            case 'generateMemberCards':
                return Configure::read('appDb.FCS_SELF_SERVICE_MODE_FOR_STOCK_PRODUCTS_ENABLED') && ($this->AppAuth->isSuperadmin() || $this->AppAuth->isAdmin());
                break;
            case 'generateMyMemberCard':
                return Configure::read('appDb.FCS_SELF_SERVICE_MODE_FOR_STOCK_PRODUCTS_ENABLED') && ($this->AppAuth->isSuperadmin() || $this->AppAuth->isAdmin() || $this->AppAuth->isCustomer());
                break;
            case 'edit':
            case 'creditBalanceSum':
                return $this->AppAuth->isSuperadmin();
                break;
            case 'profile':
                return $this->AppAuth->isSuperadmin() || $this->AppAuth->isAdmin() || $this->AppAuth->isCustomer();
                break;
            case 'delete':
                return $this->AppAuth->isSuperadmin();
                break;
            case 'changePassword':
                return $this->AppAuth->user();
                break;
            default:
                return $this->AppAuth->isSuperadmin() || $this->AppAuth->isAdmin();
                break;
        }
    }
    
    public function generateMyMemberCard()
    {
        $customerId = $this->AppAuth->getUserId();
        $this->prepareGenerateMemberCards($customerId);
    }
    
    public function generateMemberCards()
    {
        $customerIds = $this->getRequest()->getQuery('customerIds');
        $customerIds = explode(',', $customerIds);
        $this->prepareGenerateMemberCards($customerIds);
    }
    
    private function prepareGenerateMemberCards($customerIds)
    {
        if (empty($customerIds)) {
            throw new InvalidParameterException('no customer id passed');
        }
        
        $this->Customer = TableRegistry::getTableLocator()->get('Customers');
        $this->Customer->dropManufacturersInNextFind();
        $customers = $this->Customer->find('all', [
            'fields' => [
                'bar_code' => $this->AppAuth->getAuthenticate('BarCode')->getIdentifierField($this->Customer)
            ],
            'conditions' => [
                'Customers.id_customer IN' => $customerIds
            ],
            'order' => [
                'Customers.' . Configure::read('app.customerMainNamePart') => 'ASC'
            ],
            'contain' => [
                'AddressCustomers', // to make exclude happen using dropManufacturersInNextFind
            ]
        ]);
        $customers->select($this->Customer);
        $customers->select($this->Customer->AddressCustomers);
        $this->set('customers', $customers);
    }

    public function ajaxEditGroup()
    {
        $customerId = (int) $this->getRequest()->getData('customerId');
        $groupId = (int) $this->getRequest()->getData('groupId');

        if (! in_array($groupId, array_keys(Configure::read('app.htmlHelper')->getAuthDependentGroups($this->AppAuth->getGroupId())))) {
{'fraction_non_alphanumeric': 0.1364916146407149, 'fraction_numerical': 0.0007344840249724568, 'mean_word_length': 2.5460069444444446, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 136, 'https://': 4, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3309566', 'n_tokens_mistral': 2249, 'n_tokens_neox': 2199, 'n_words': 386}