CHeckbox editable only by admin

General questions about CMSimple
Tata
Posts: 2507
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

CHeckbox editable only by admin

Postby Tata » Sun Oct 09, 2016 10:03 am

Here is a testpage I am working on. Thanks to many of you during recent week, the page seems to be shaped as expected. I like to include is a checbox for each item in restarant's menu showing if that specific item is actually available. This shall be controled by admin. The checkbox is there but aditable only by visitiors (or in preview by admin too). How to make it to have it editable only in backend and readonly for visitors?
Image
the used code is (used/copied/pasted for all meals):

Code: Select all

<h3>Predjedlo 1</h3>
<
div>
     <div>
          <a class="zoom" href="./userfiles/images/restauracia/kuchyna_02.jpg"><img class="jedlo" src="./userfiles/images/restauracia/kuchyna_02.jpg" alt="Demo" width="800" height="600"></a>
     </div>
     <div>Popis</div>
     <div>Porcia</div>
     <div>Cena</div>
     <div>Poznámka (dezert, nápoj)</div>
     <div class="v_ponuke">
          <input id="v_ponuke" type="checkbox" name="check" value="None" checked="checked"><label for="v_ponuke">Dnes v ponuke</label>
     </div>
</
div
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

Tata
Posts: 2507
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

Re: CHeckbox editable only by admin

Postby Tata » Sun Oct 09, 2016 4:49 pm

I made a desperate attempt:
wrote a function in userfuncs

Code: Select all

<?php
function fcn_readonly
(){
     if(!$adm == 'true'){
          echo "readonly";
     }else{
          echo "";
     }
}

and put on page

Code: Select all

<input id="v_ponuke" type="checkbox" name="check" value="None" checked="checked" readonly="{{{fcn_readonly}}}"><label for="v_ponuke">

Seems nice to me, but without expected result. The inserted function is not save at all and the checkbox is editable only in frontend. Even if there is directly define readonly="readonly", the checkbox is editable for visitors.
I have found small hint

Code: Select all

<input id="v_ponuke" onclick="this.checked=!this.checked;" type="checkbox" name="check" value="None" checked="checked"
but how to include a test if admin is logged in and allow him to change the checkboc value wothout editing in source mode?
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.

cmb
Posts: 12007
Joined: Tue Jun 21, 2011 11:04 am
Location: Mü-Sa, RLP, DE
Contact:

Re: CHeckbox editable only by admin

Postby cmb » Mon Oct 10, 2016 6:56 am

The simplest solution might be not to use a checkbox at all, but rather prepare one or two CSS classes which the admin can assign to the text "Dnes v ponuke" in the editor. A single class (say .available) might be easier to handle for the admin.
Christoph M. Becker –Plugins for CMSimple_XH, but not for CMSimple 4+

Tata
Posts: 2507
Joined: Tue May 20, 2008 5:34 am
Location: Slovakia
Contact:

Re: CHeckbox editable only by admin

Postby Tata » Mon Oct 10, 2016 7:07 am

Correct. I have got to a solution during the night as I haad found no other on internet.
I added one more column to the "meal tables" and ther a formated DIV which either remains empty or the admin put in a special character from the editor showing that the meal is actuallly available. I upload things soon to my test space.
Thanks anyway. (ANz simply clickable solution would be more comfortable, however :-) )

SOLVED:
I have created two icons for available/inavailable and dropped them right behind the heading in the menu but visible only while logged in. Drag/drop is the simplest way to get them on the page. The same way the daily menu is actualized (the title of the "meal page" is dragget to the page with daily menu. This way the visitors may klick in the menu to see a description, foto etc.
CMSimple.sk
It's no shame to ask for an answer if all efforts failed.
But it's awful to ask without any effort to find the answer yourself.


Return to “General”

Who is online

Users browsing this forum: No registered users and 2 guests