<?php
 class RoleGlobal {
 public static $role = null;
 public $roles;
 public function __construct() {
 $this->roles = new \stdClass();
 $this->roles->viewStaff = Role::make('00101', lang('role.view'), lang('role.staff'), 1);
 $this->roles->createStaff = Role::make('00102', lang('role.create'), lang('role.staff'), 1);
 $this->roles->updateStaff = Role::make('00103', lang('role.update'), lang('role.staff'), 1);
 $this->roles->deleteStaff = Role::make('00104', lang('role.delete'), lang('role.staff'), 1);
 $this->roles->viewPositions = Role::make('01601', lang('role.view'), lang('role.positions'),1);
 $this->roles->createPositions = Role::make('01602', lang('role.create'), lang('role.positions'),1);
 $this->roles->updatePositions = Role::make('01603', lang('role.update'), lang('role.positions'),1);
 $this->roles->deletePositions = Role::make('01604', lang('role.delete'), lang('role.positions'),1);
 $this->roles->viewUser = Role::make('00201', lang('role.view'), lang('role.user'), 1);
 $this->roles->createUser = Role::make('00202', lang('role.create'), lang('role.user'), 1);
 $this->roles->updateUser = Role::make('00203', lang('role.update'), lang('role.user'), 1);
 $this->roles->deleteUser = Role::make('00204', lang('role.delete'), lang('role.user'), 1);
 $this->roles->viewGroupUser = Role::make('01301', lang('role.view'), lang('role.group_user'), 1);
 $this->roles->createGroupUser = Role::make('01302', lang('role.create'), lang('role.group_user'), 1);
 $this->roles->updateGroupUser = Role::make('01303', lang('role.update'), lang('role.group_user'), 1);
 $this->roles->deleteGroupUser = Role::make('01304', lang('role.delete'), lang('role.group_user'), 1);
 $this->roles->enterSuperAdmin = Role::make('00302', lang('role.view_super_admin'), lang('role.super_admin'));
 $this->roles->superUserManager = Role::make('00301', lang('role.manage_super_admin'), lang('role.super_admin'));
 $this->roles->superGroupUserManager = Role::make('00308', lang('role.group_user_manage'), lang('role.super_admin'));
 $this->roles->superStaffManager = Role::make('00303', lang('role.staff_manage'), lang('role.super_admin'));
 $this->roles->superStoreManager = Role::make('00304', lang('role.customer_manage'), lang('role.super_admin'));
 $this->roles->superCityManager = Role::make('00305', lang('role.city_manage'), lang('role.super_admin'));
 $this->roles->superCompanyTypeManager = Role::make('00306', lang('role.company_type_manage'), lang('role.super_admin'));
 $this->roles->superCodeWorkManager = Role::make('00307', lang('role.code_work_manage'), lang('role.super_admin'));
 $this->roles->viewAllBranch = Role::make('00401', lang('role.view_all'), lang('role.branchs_name'), 1);
 $this->roles->createBranch = Role::make('00403', lang('role.create'), lang('role.branchs_name'));
 $this->roles->updateBranch = Role::make('00404', lang('role.update'), lang('role.branchs_name'));
 $this->roles->deleteBranch = Role::make('00405', lang('role.delete'), lang('role.branchs_name'));
 $this->roles->viewFloor = Role::make('01402', lang('role.view'), lang('role.floor_name'), 1);
 $this->roles->createFloor = Role::make('01403', lang('role.create'), lang('role.floor_name'), 1);
 $this->roles->updateFloor = Role::make('01404', lang('role.update'), lang('role.floor_name'),1);
 $this->roles->deleteFloor = Role::make('01405', lang('role.delete'), lang('role.floor_name'),1);
 $this->roles->viewCustomer = Role::make('00001', lang('role.view'), lang('role.customer'),1);
 $this->roles->createCustomer = Role::make('00002', lang('role.create'), lang('role.customer'),1);
 $this->roles->updateCustomer = Role::make('00003', lang('role.update'), lang('role.customer'),1);
 $this->roles->deleteCustomer = Role::make('00004', lang('role.delete'), lang('role.customer'),1);
 $this->roles->viewCustomerAll = Role::make('00005', lang('role.view_all'), lang('role.customer'),1);
 $this->roles->viewHotCustomer = Role::make('00501', lang('role.view'), lang('role.hot_customer'),1);
 $this->roles->createHotCustomer = Role::make('00502', lang('role.create'), lang('role.hot_customer'),1);
 $this->roles->updateHotCustomer = Role::make('00503', lang('role.update'), lang('role.hot_customer'),1);
 $this->roles->deleteHotCustomer = Role::make('00504', lang('role.delete'), lang('role.hot_customer'),1);
 $this->roles->viewHotCustomerAll = Role::make('00505', lang('role.view_all'), lang('role.hot_customer'),1);
 $this->roles->HotCustomerCheckRule = Role::make('00506', lang('role.hot_customer_check_rule'), lang('role.hot_customer'),1);
 $this->roles->viewScheduler = Role::make('00601', lang('role.view'), lang('role.scheduler'),1);
 $this->roles->createScheduler = Role::make('00602', lang('role.create'), lang('role.scheduler'),1);
 $this->roles->updateScheduler = Role::make('00603', lang('role.update'), lang('role.scheduler'),1);
 $this->roles->deleteScheduler = Role::make('00604', lang('role.delete'), lang('role.scheduler'),1);
 $this->roles->viewSchedulerAll = Role::make('00605', lang('role.view_all'), lang('role.scheduler'),1);
 $this->roles->viewReserve = Role::make('00701', lang('role.view'), lang('role.reserve'),1);
 $this->roles->createReserve = Role::make('00702', lang('role.create'), lang('role.reserve'),1);
 $this->roles->updateReserve = Role::make('00703', lang('role.update'), lang('role.reserve'),1);
 $this->roles->deleteReserve = Role::make('00704', lang('role.delete'), lang('role.reserve'),1);
 $this->roles->viewReserveAll = Role::make('00705', lang('role.view_all'), lang('role.reserve'),1);
 $this->roles->viewVisitCustomer = Role::make('00801', lang('role.view'), lang('role.visit_customer'),1);
 $this->roles->createVisitCustomer = Role::make('00802', lang('role.create'), lang('role.visit_customer'),1);
 $this->roles->updateVisitCustomer = Role::make('00803', lang('role.update'), lang('role.visit_customer'),1);
 $this->roles->deleteVisitCustomer = Role::make('00804', lang('role.delete'), lang('role.visit_customer'),1);
 $this->roles->viewVisitCustomerAll = Role::make('00805', lang('role.view_all'), lang('role.visit_customer'),1);
 $this->roles->viewMessage = Role::make('00901', lang('role.view'), lang('role.message'),1);
 $this->roles->createMessage = Role::make('00902', lang('role.create'), lang('role.message'),1);
 $this->roles->updateMessage = Role::make('00903', lang('role.update'), lang('role.message'),1);
 $this->roles->deleteMessage = Role::make('00904', lang('role.delete'), lang('role.message'),1);
 $this->roles->viewMessageAll = Role::make('00905', lang('role.view_all'), lang('role.message'),1);
 $this->roles->viewFloorManager = Role::make('01000', lang('role.view_floor_manager'), lang('role.floor_manager'),1);
 $this->roles->designFloorManager = Role::make('01001', lang('role.design_floor_manager'), lang('role.floor_manager'),1);
 $this->roles->settingFloorManager = Role::make('01002', lang('role.setting_floor_manager'), lang('role.floor_manager'),1);
 $this->roles->viewPurposes = Role::make('01101', lang('role.view'), lang('role.purposes'),1);
 $this->roles->createPurposes = Role::make('01102', lang('role.create'), lang('role.purposes'),1);
 $this->roles->updatePurposes = Role::make('01103', lang('role.update'), lang('role.purposes'),1);
 $this->roles->deletePurposes = Role::make('01104', lang('role.delete'), lang('role.purposes'),1);
 $this->roles->viewDrinks = Role::make('01201', lang('role.view'), lang('role.drinks'),1);
 $this->roles->createDrinks = Role::make('01202', lang('role.create'), lang('role.drinks'),1);
 $this->roles->updateDrinks = Role::make('01203', lang('role.update'), lang('role.drinks'),1);
 $this->roles->deleteDrinks = Role::make('01204', lang('role.delete'), lang('role.drinks'),1);
 $this->roles->viewCars = Role::make('01501', lang('role.view'), lang('role.cars'),1);
 $this->roles->createCars = Role::make('01502', lang('role.create'), lang('role.cars'),1);
 $this->roles->updateCars = Role::make('01503', lang('role.update'), lang('role.cars'),1);
 $this->roles->deleteCars = Role::make('01504', lang('role.delete'), lang('role.cars'),1);
 $this->roles->createCarCompartment = Role::make('01902', lang('role.create'), lang('CarCompartment_model.name'),1);
 $this->roles->updateCarCompartment = Role::make('01903', lang('role.update'), lang('CarCompartment_model.name'),1);
 $this->roles->deleteCarCompartment = Role::make('01904', lang('role.delete'), lang('CarCompartment_model.name'),1);
 $this->roles->viewCarCompartment = Role::make('01905', lang('role.view'), lang('CarCompartment_model.name'),1);
 $this->roles->viewCompartmentManager = Role::make('01901', lang('role.view'), lang('role.compartment_manager'),1);
 }
 public function toList() {
 $type = area_name() == 'super-admin' ? 0 : 1;
 $_roles = [];
 foreach($this->roles as $role) {
 if($type && $role->type != $type) continue;
 if(!isset($_roles[$role->group])) {
 $_roles[$role->group] = [];
 }
 $_roles[$role->group][$role->key] = $role->name;
 }
 return $_roles;
 }
 public $lastRoleCalled = false;
 public function __get($name) {
 $this->lastRoleCalled = $name;
 return ($this->roles->$name)->key;
 }
 public function getRole($key) {
 return $this->roles->$key;
 }
 }
 class Role {
 public $key;
 public $name;
 public $group;
 public $type;
 public function __construct($key, $name, $group = '', $type) {
 $this->key = $key;
 $this->name = $name;
 if(!$group) {
 $group = substr($key, 0, 3);
 }
 $this->group = $group;
 $this->type = $type;
 }
 public static function make($key, $name, $group = '', $type = 0) {
 return new Role($key, $name, $group, $type);
 }
 public function __toString() {
 return $this->key;
 }
 }
 RoleGlobal::$role = new RoleGlobal();
 