Esempio n. 1
0
 /**
  * Add Custom User Role
  *
  * @param string $new_role name of new custom role
  * @return bool
  */
 public function addCustomRole($h, $new_role = '', $base_role = 'default')
 {
     if (!$new_role) {
         return false;
     }
     $new_role = mb_strtolower($new_role, 'UTF-8');
     // test if this role name is reserved:
     $default_roles = $this->getDefaultRoles();
     if (in_array($new_role, $default_roles)) {
         return false;
     }
     // test if this role name is already a custom role:
     $custom_roles = $this->getCustomRoles($h);
     if ($custom_roles && in_array($new_role, $custom_roles)) {
         return false;
     }
     // add new role to custom roles
     if (!$custom_roles) {
         $custom_roles = array();
     }
     array_push($custom_roles, $new_role);
     // check custom_roles row exists in the database:
     //$result = \HotaruModels\Miscdata::getCurrentValue('custom_roles');
     $result = \Hotaru\Models2\Miscdata::getCurrentValue($h, 'custom_roles');
     // update or insert accordingly
     if ($result) {
         \Hotaru\Models2\Miscdata::update($h, serialize($custom_roles), 'custom_roles');
         //$sql = "UPDATE " . TABLE_MISCDATA . " SET miscdata_value = %s, miscdata_updateby = %d WHERE miscdata_key = %s";
         //$h->db->query($h->db->prepare($sql, serialize($custom_roles), $h->currentUser->id, 'custom_roles'));
     } else {
         \Hotaru\Models2\Miscdata::add($h, serialize($custom_roles), 'custom_roles');
         //$sql = "INSERT INTO " . TABLE_MISCDATA . " (miscdata_key, miscdata_value, miscdata_updateby) VALUES(%s, %s, %d)";
         //$h->db->query($h->db->prepare($sql, 'custom_roles', serialize($custom_roles), $h->currentUser->id));
     }
     // Next, update Hotaru's base permissions
     $base_perms = $h->getDefaultPermissions('all', 'base');
     $base_perms = $this->copyRolePerms($h, $base_perms, $new_role, $base_role);
     $h->updateDefaultPermissions($base_perms, 'base');
     // Next, update Hotaru's site permissions
     $site_perms = $h->getDefaultPermissions('all', 'site');
     $site_perms = $this->copyRolePerms($h, $site_perms, $new_role, $base_role);
     $h->updateDefaultPermissions($site_perms, 'site');
     return true;
 }
Esempio n. 2
0
 /**
  * 
  * @param type $h
  * @param type $type
  */
 public function miscdata($h, $key = '', $cache = 'true')
 {
     //$data = \Hotaru\Models\Miscdata::getCurrentValue($key);
     $data = \Hotaru\Models2\Miscdata::getCurrentValue($h, $key, $cache);
     return $data;
 }