The following warnings occurred:
Warning [2] Undefined array key "threadviews_countguests" - Line: 745 - File: showthread.php PHP 8.1.31 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/showthread.php 745 errorHandler->error_callback
Warning [2] Undefined array key "allowautourl" - Line: 584 - File: inc/class_parser.php PHP 8.1.31 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/inc/class_parser.php 584 errorHandler->error_callback
/inc/class_parser.php 228 postParser->parse_mycode
/inc/functions_post.php 830 postParser->parse_message
/showthread.php 916 build_postbit
Warning [2] Undefined property: MyLanguage::$thread_modes - Line: 46 - File: showthread.php(1650) : eval()'d code PHP 8.1.31 (Linux)
File Line Function
/inc/class_error.php 153 errorHandler->error
/showthread.php(1650) : eval()'d code 46 errorHandler->error_callback
/showthread.php 1650 eval




Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Frontainer
#11
BTW: Simple user permissions (logged in, not-logged in) are just fine, but however, you may have even more fun and flexibility by adding a new user "roles" field to your Users category in ItemManager:

[Image: roles_field.png?dl=1]

This way you can show relevant content depending on the user role, for example:

PHP Code:
if($role->value == 'user') {
 
   echo 'Content for users only';
} elseif(
$role->value == 'admin') {
 
   echo 'Content for admins only';
} elseif(
$role->value == 'superuser') {
 
   echo 'Superusers content';
} else {
 
   echo 'User has no role selected';


Your complete code in template.php file world might then look like this:

PHP Code:
if(!empty($_SESSION['loggedin'])) {
 
   $manager = new IManager();
 
   $catClass $manager->getCategoryClass();
 
   $category $catClass->getCategory('name=Users');
 
   $itemClass $manager->getItemClass();
 
   $itemClass->limitedInit($category->get('id'), (int)$_SESSION['userid']);
 
   $user $itemClass->items[(int)$_SESSION['userid']];
 
   if(!$user) {die('User data not found');}
 
   $role $user->fields->roles;

 
   if($role->value == 'user') {
 
       echo 'Content for users only';
 
   } elseif($role->value == 'admin') {
 
       echo 'Content for admins only';
 
   } elseif($role->value == 'superuser') {
 
       echo 'Superusers content';
 
   } else {
 
       echo 'User has no role selected';
 
   }


Note: If users already exist, these users may fail to be synced to new "roles" field, you should re-save/update users in admin manually or by ItemManager API call:

PHP Code:
<?php
$manager 
= new IManager();
$catClass $manager->getCategoryClass();
$category $catClass->getCategory('name=Users');
$itemClass $manager->getItemClass();
$itemClass->init($category->get('id'));
foreach(
$itemClass->items as $user) {
 
   if($user->save()) {
 
       echo '<p>User name: <strong>'.htmlspecialchars($user->name).'</strong>  was successfully updated</p>';
 
   }

Reply


Messages In This Thread
Frontainer - by Bigin - 2016-02-22, 23:48:10
RE: Frontainer - by Tzvook - 2016-02-24, 07:20:45
RE: Frontainer - by Bigin - 2016-02-24, 07:25:28
RE: Frontainer - by Tzvook - 2016-02-24, 07:39:28
RE: Frontainer - by Bigin - 2016-02-24, 07:50:04
RE: Frontainer - by Tzvook - 2016-02-24, 07:54:03
RE: Frontainer - by Bigin - 2016-02-24, 07:59:36
RE: Frontainer - by DesruX - 2016-04-12, 07:55:41
RE: Frontainer - by Bigin - 2016-04-12, 17:41:37
RE: Frontainer - by Bigin - 2016-04-13, 00:17:33
RE: Frontainer - by DesruX - 2016-04-13, 00:36:22
RE: Frontainer - by Bigin - 2016-04-13, 01:37:49
RE: Frontainer - by DesruX - 2016-04-13, 04:24:49
RE: Frontainer - by Bigin - 2016-04-13, 05:25:05
RE: Frontainer - by DesruX - 2016-04-13, 05:32:45
RE: Frontainer - by Bigin - 2016-04-13, 05:51:48
RE: Frontainer - by DesruX - 2016-04-15, 06:45:34
RE: Frontainer - by Bigin - 2016-04-15, 19:39:53
RE: Frontainer - by Bigin - 2016-04-12, 18:08:27
RE: Frontainer - by DesruX - 2016-04-12, 23:49:06
RE: Frontainer - by Bigin - 2016-04-13, 00:20:00
RE: Frontainer - by DesruX - 2016-04-13, 00:31:16
RE: Frontainer - by Bigin - 2016-04-12, 20:14:09
RE: Frontainer - by Bigin - 2016-04-15, 20:12:41
RE: Frontainer - by jeckyl - 2017-02-07, 01:55:19
RE: Frontainer - by Bigin - 2017-02-07, 03:58:00
RE: Frontainer - by jeckyl - 2017-02-07, 04:36:08
RE: Frontainer - by Bigin - 2017-02-07, 05:16:52
RE: Frontainer - by jeckyl - 2017-02-07, 06:13:24
RE: Frontainer - by Bigin - 2017-02-07, 08:49:33
RE: Frontainer - by jeckyl - 2017-02-07, 09:14:22
RE: Frontainer - by nicco - 2017-05-12, 19:26:45
RE: Frontainer - by Bigin - 2017-05-12, 20:38:15
RE: Frontainer - by nicco - 2017-05-12, 23:28:17
RE: Frontainer - by Bigin - 2017-05-13, 00:58:52
RE: Frontainer - by nicco - 2017-05-13, 02:11:24
RE: Frontainer - by Bigin - 2017-05-13, 02:51:45
RE: Frontainer - by nicco - 2017-05-13, 03:04:30
RE: Frontainer - by Bigin - 2017-05-13, 03:09:48
RE: Frontainer - by Carlos - 2017-05-13, 03:19:09
RE: Frontainer - by Bigin - 2017-05-13, 03:28:10
RE: Frontainer - by Stéphane - 2020-04-13, 03:40:16
RE: Frontainer - by Bigin - 2020-04-13, 04:16:35
RE: Frontainer - by Stéphane - 2020-04-13, 08:02:32
RE: Frontainer - by Bigin - 2020-04-13, 20:32:51
RE: Frontainer - by Stéphane - 2020-04-13, 22:46:48



Users browsing this thread: 3 Guest(s)