Conditionally show as read only to certain group

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
User avatar
urichard
Veteran Member
Posts: 87
Joined: 2018-11-01 12:11

Conditionally show as read only to certain group

Post by urichard » 2022-07-20 06:40

Hi,

I want to conditionally énable the field "paid", "unpaid" and "canceled" for certain users?

I still want the field to be displayed but must be read-only and shouldn't be able to change it for a certain group but then for another group should be able to change the status from unpaid to paid?

Is this possible and how do I do this, please give me step by step guide as I have zero coding skills and still learning

Kind Regards,
Richard
[email protected][/color]

Kind Regards
Richard

User avatar
urichard
Veteran Member
Posts: 87
Joined: 2018-11-01 12:11

Re: Conditionally show as read only to certain group

Post by urichard » 2022-07-21 06:56

Can someone help me, please?
[email protected][/color]

Kind Regards
Richard

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Conditionally show as read only to certain group

Post by jsetzer » 2022-07-21 08:34

Hi, honestly speaking, if you request a solution for your problem and want us to elaborate and publish a step-by-step guide for your specific, individual requirement within one day, you should give some more information on your database model and show the code you have tried so far.

Please don't get me wrong: From my experience with this forum, giving more information and being more patient could increase the chance that others are willing to spend their free time on your specific problem.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Conditionally show as read only to certain group

Post by jsetzer » 2022-07-21 14:52

Maybe Olaf's approach can help you:
viewtopic.php?t=3308
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

User avatar
urichard
Veteran Member
Posts: 87
Joined: 2018-11-01 12:11

Re: Conditionally show as read only to certain group

Post by urichard » 2022-07-21 16:14

Hi Jsetzer,

I understand and apologize for being so impatient.

Meaby I didn't explain myself properly, I'm using the online invoices open source web application from Appgini and on the invoices table in one of the fields, the status can be changed to paid, unpaid or cancel.

When I have let's say 4 users in the group that have access to the table I would like all 4 of them to be able to add records to the table for all the fields except 1 of the fields on the same table should not be editable but 'read only' unless one of the users have a higher level/ admin privileges.

I did have a look at Olafs approach as you said but unfortunately, he is placing restrictions on the whole table, I instead want it only on 1 specific field in the table, also he is using Appgini helper and I do not yet have access to that.

If getting Appgini helper is the only way forward then I will most probably get it but Olaf has mentioned in his post that "You can easily LOCK and HIDE fields for specific user groups. Single users are not supported at this time." and that "AppGini (AG) in the current version 5.81 does not support field specific permissions" this he posted 12 Nov 2019, is this still not supported by Appgini even if I get Appgini helper or is there another method I can use to get there?

Kind Regards,
Richard
[email protected][/color]

Kind Regards
Richard

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Conditionally show as read only to certain group

Post by jsetzer » 2022-07-21 17:22

There are no field-level permissions in latest AG 22.14.

You can use pure Javascript OR AppGini Helper Javascript Library for hiding or locking single fields. You will need some additional PHP code for finding out the current user/group and then, depending on user/group, dynamically write Javascript from PHP.

Or you can use client side (javascript) AJAX for fetching permissions from a serverside Php script, then modify UI in browser (Javascript)

If you ask me, this is not trivial and nothing for beginners. I don't know a working, bulletproof, version-compatible and hooks-only out-of-the-box solution for your specific requirements, but hopefully someone will find the time for developing and publishing such.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

User avatar
urichard
Veteran Member
Posts: 87
Joined: 2018-11-01 12:11

Re: Conditionally show as read only to certain group

Post by urichard » 2022-07-21 17:44

Thanks Jsetzer, even though beginner its helping to point me into the direction i need to go.

Im considering appgini helper

If anyone does create a "working, bulletproof, version-compatible and hooks-only out-of-the-box solution for your specific requirements" please do share lol

Regards,
Richard
[email protected][/color]

Kind Regards
Richard

User avatar
urichard
Veteran Member
Posts: 87
Joined: 2018-11-01 12:11

Re: Conditionally show as read only to certain group

Post by urichard » 2022-10-13 09:50

Hi Jsetzer,

Im considering getting Appgini helper but to be honnest it made me abit scarred when you mentioned "You will need some additional PHP code for finding out the current user/group and then, depending on user/group, dynamically write Javascript from PHP."

I have no idea how to code so is there meaby a template i can use or can you point me in the right direction how to do this using Appgini Helper?
[email protected][/color]

Kind Regards
Richard

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Conditionally show as read only to certain group

Post by jsetzer » 2022-10-13 12:46

Hi, AppGini Helper JavaScript Library is client side (browser) only. It has nothing to do with Server side (server/database). But you can use PHP to pass data from server to client, then use it in JavaScript. I can provide a simple example later today.

A little programming knowledge is required if you want to program software and want to change the no-code generated standard web application.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 347
Joined: 2018-03-04 09:30
Location: David

Re: Conditionally show as read only to certain group

Post by D Oliveira » 2022-10-13 23:28

Here's some help:

Code: Select all


<div id="my_div">
A Text Value
</div>

<script type="text/javascript">

	jQuery(function(){
		var pass_val = 'passing_value';
		var received_val = null;
			$j.ajax({
				url: 'ajax-file.php',
				data: { ajax_pass: pass_val },
				success: function(data){
					if (data) {

						console.log(data);

                          			 received_val = data;

                          			 document.getElementById('my_div').innerHTML = received_val;

									
					}else{

						console.log('no data');
								
					}
				}
			});

	});

</script>

<?php

	// ajax-file.php

	$currDir = dirname(__FILE__) . ''; // use /.. for hooks
	include("$currDir/defaultLang.php");
	include("$currDir/language.php");
	include("$currDir/lib.php");

	$con = mysqli_connect($dbServer, $dbUsername, $dbPassword);
	mysqli_select_db($con,$dbDatabase);

	//$mi = getMemberInfo();

	$ajax_pass = makesafe($_REQUEST['ajax_pass']);

	$query = "SELECT my_column FROM table WHERE ID = '{$ajax_pass}'";

	$query_done = sqlValue($query);

    echo $query_done;

?>

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Conditionally show as read only to certain group

Post by jsetzer » 2022-10-14 08:50

Put the following code in your TABLENAME_dv hook-function of your hooks/TABLENAME.php file:

(Replace TABLENAME)

Code: Select all

// file: hooks/TABLENAME.php
function TABLENAME_dv($selectedID, $memberInfo, &$html, &$args)
{
    $current = [
        "record" => [
            "pk" => $selectedID,
            "tn" => substr(basename($_SERVER['SCRIPT_FILENAME']), 0, -9)
        ], 
        "user" => [
            id" => $memberInfo['username'],
            "name" => $memberInfo['username'],
            "email" => $memberInfo['email'],
            "custom" => array_combine(array_map(function($i){ return config('adminConfig')["custom{$i}"];}, range(1,4)), $memberInfo['custom']),
            "is_admin" => $memberInfo['admin'],
        ],
        "group" => [
            "id" => $memberInfo["groupID"],
            "name" => $memberInfo["group"]
        ],
    ];
    $html .= "<script>const current = " . json_encode($current, JSON_PRETTY_PRINT) . "</script>";

    // other code

}
Save the file, then reload the Detail View of your TABLENAME table.

Now you will have data passed from server side (PHP) to the client side (Browser) in variable current which you can use in Javascript.

chrome_0DDx1JSvSP.png
chrome_0DDx1JSvSP.png (10.88 KiB) Viewed 1221 times

You can use that variable (actually: object) in your Javascript, for example:

Code: Select all

// file: hooks/TABLENAME-dv.js
alert(current.user.name);
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

Post Reply