Jump to content

Page Edit Per User Module - Specific PHP Selector for editable pages, Multi-User-System etc...


Orkun
 Share

Recommended Posts

Hello Processwire Community

Lets say I have a Multi-User-System where I can create/update as "normal" user new events, dates, multimediapages, imagepages etc....

As Admin I can create organisers(owners) and assign them respectively to specific users.

Module for creating/updating pages: Fredi - Friendly Frontend Editor

Scenario: Add new Imagepage under Multimedia > Images

Important Fields

select_organiser(FieldtypePage)(btw. this field is assigned to the user template)

PHP-Selector for "select_organiser"

if(wire('user')->isSuperuser()){
    return $pages->find("template=organiser");
}
else{
    return $pages->find("template=organiser, id=".wire('user')->select_organiser);
}

Templates

image-index(is assigned to Image-Page)

-> Fields: only title

- > images-index.php

Only show the image pages which has the same organiser like the current user.

<?php
$out .="<h3>$title verwalten</h3>

				<div class='span11'>
					<div class='btn-pos-1 add'>"
					.$fredi->setText("<i class='fa fa-plus'></i> Bild erfassen")->hideTabs("children|delete|settings")->addPage("image", "title|select_organiser", $pages->get(1153)).
					"</div>
					<table id='example' class='row-border' cellspacing='0' width='100%'>
				        <thead>
				            <tr>
				              <th>ID</th>
				              <th>Bildname</th>
				              <th>Bild</th>
				              <th>Beschreibung</th>
				              <th>Veranstalter</th>
				              <th>aktualisiert</th>
				              <th></th>
				              <th></th>

				            </tr>
				        </thead>

				        <tbody>";

					        if($user->isSuperuser()){
					        	$images = $pages->find("template=image");
					        }
					        else{
					        	
					        	$images = $pages->find("template=image, select_organiser=$user->select_organiser");
					        }
					     
					        foreach ($images as $i_item) {
					        	if($i_item->image){
					        		$thumb = $i_item->image->size(50, 50);
					        	}
					        	$out .= "<tr>
					        	         <td>{$i_item->id}</td>
					        	         <td>{$i_item->title}</td>
					        	         <td><a class='large_img' href='{$i_item->image->url}' ><img src='{$thumb->url}' /></a></td>
					        	         <td>{$i_item->image_body}</td>
					        	         <td>{$i_item->select_organiser->title}</td>
					        	         <td>".date('Y-m-d', $i_item->modified)."</td>
					        	         <td><a href='{$i_item->url}'><i class='fa fa-eye'></i></td>
					        	         <td>".$fredi->setText("<i class='fa fa-pencil'></i>")->renderAll($i_item)."</td>
					        	         </tr>";
					        }
		$out .= "		</tbody>
			    	</table>
				</div>";

images(is assinged to children-items of Image-Page)

-> Fields: title, image, image_body, select_organiser

-> images.php

At the beginnnig of the template it checks if the select_organiser of the current user is the same as the select_organiser of the current image page.

<?php
if($user->select_organiser == $page->select_organiser || $user->isSuperuser()){

$out .= "<h3>{$page->parent->title} Details</h3>
         <div class='span8'>
            <table class='detail-view table table-striped table-condensed'>";

            $out .= "<tr class='odd'><th>ID</th><td>{$page->id}</td></tr>";

            //get all fields:
            $all_fields = $page->fields;

            foreach($all_fields as $field){
          

                if($field->type == "FieldtypeImage"){
                     $out .= "<tr class='odd'><th>{$field->label}</th><td>{$page->get($field->name)->url}</td></tr>";
                }
                else if($field->type == "FieldtypePage"){
                     $out .= "<tr class='odd'><th>{$field->label}</th><td>{$page->get($field->name)->title}</td></tr>";
                }
                else{

                  $out .= "<tr class='odd'><th>{$field->label}</th><td>{$page->get($field->name)}</td></tr>";
               }
            }

            $out .= "<tr class='odd'><th>erstellt</th><td>".date("Y-m-d H:i:s", $page->created)."</td></tr>
                     <tr class='even'><th>aktualisiert</th><td>".date("Y-m-d H:i:s", $page->modified)."</td></tr>
            </table>
        </div>

        <div class='span3'>
            <div id='sidebar'>
                <ul class='well nav nav-list' id='yw1'>
                    <li class='nav-header nav-header'>Aktionen</li>
                    <li><a href='{$page->parent->url}'><i class='fa fa-list'></i> Bilder auflisten</a></li>
                    <li>".$fredi->setText("<i class='fa fa-pencil'></i> Bild bearbeiten")->renderAll($page)."</li>
                </ul>
                <br />        
            </div>
        </div>";

}
else{
    $session->redirect($error404->url);
}

The Problem of this System is that the user still can access to image-pages in the backend that dont have the same organiser. Its only view protected.

So finally my Question: Can i specifiy a PHP-Selector for the editable pages for the Page Edit Per User Module.

Like:


return $pages->find("template=images, id=".wire('user')->select_organiser);

So that the user can edit the image - pages which has the same organiser like him?

Pagetree Structure and some screenshots of the interfaces for visualization:

Pagetree Structure:

Home(Login-Page)

   - Dashboard(Intro-Page)

     -- Events(visible for superuser and user with role: company)

     -- Agenda/Dates(visible for superuser and user with role: company)

     -- Multimedia(visible for superuser and user with role: company)

       --- Images(template: image-index)

          ---- example-img.jpg(template: image)

          ...

       --- Videos

     -- Profile(visible for superuser and user with role: company)

     -- Organisers(Only visible for Superuser)

        --- Organiser-Profiles

           ---- XYZ AG

           ...

        --- Adresses

        --- Locations

     -- Settings(Only visible for Superuser)

     -- Logout

Image - Overview Page

post-3125-0-57488000-1444212375_thumb.pn

Image - Detail Page

post-3125-0-88676900-1444212380_thumb.pn

PS: Sorry for the long post :P:lol:

Link to comment
Share on other sites

I thought that i could bypass the problem, when I only give view permission to the users with the role "company" so that they cant access the backend. But the problem is then, that they cant create/update pages from the Frontent with the modal edit windows of fredi.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Joachim
      Long time user and huge fan of PW, but this time I can't find an answer to my question this time:
      For my social media buttons, I have a Repeater field called var_link_web with two fields: one is for the URL, and the other is an Images field containing two images that are used as a background-image for a <div>, of which the second is the ':hover' version (although activated through JavaScript here). 
      There are four instances of this Repeater, of which two are 'turned off'.
      I use the following PHP in my _main.php to call them, wrapped in <p><?php == ?></p>:
      $s_m_button = $variables->var_link_web; foreach($s_m_button as $button){ $button_image = $button->var_link_image->first->height(80); $button_image2 = $button->var_link_image->eq(1)->height(80); echo " <a href='$button->var_link_url'> <div class='image_link' style='background-image:url({$button_image->url})' onMouseOver='this.style.backgroundImage=url({$button_image2->url})' onMouseOut='this.style.backgroundImage=url({$button_image->url})'> </div> </a>"; }; ($variables leads to an unpublished page with several fields I want to have easy access to, and is defined in _init.php.)
      However, this gives me the following result:

      I have no idea where the extra <p>'s come from. The URL field has the 'HTML Entity Encoder' turned on. What's even weirder is that the HTML source file seemingly renders correctly:
      <p> <a href='https://www.facebook.com/'> <div class='image_link' style='background-image:url(/site/assets/files/1045/icons-facebook-square.0x80.png)' onMouseOver='this.style.backgroundImage="url(/site/assets/files/1045/icons-facebook-square2.0x80.png)"' onMouseOut='this.style.backgroundImage="url(/site/assets/files/1045/icons-facebook-square.0x80.png)"'> </div> </a> <a href='https://www.instagram.com/'> <div class='image_link' style='background-image:url(/site/assets/files/1046/icons-instagram-square.0x80.png)' onMouseOver='this.style.backgroundImage="url(/site/assets/files/1046/icons-instagram-square2.0x80.png)"' onMouseOut='this.style.backgroundImage="url(/site/assets/files/1046/icons-instagram-square.0x80.png)"'> </div> </a> </p> Removing the JavaScript has no effect. I'm probably missing something obvious, but am at a loss here.
       
      Thank you in advance!
    • By Robin S
      Lister Selector
      A Process module that uses Lister/ListerPro, but with a selector string input instead of the normal InputfieldSelector filters.
      Features
      For power users, typing a selector string is often faster and more intuitive than fiddling with InputfieldSelector. It also lets you copy/paste selector strings that you might be using somewhere else in your code.
      Allows the Lister rows to be sorted by multiple fields (not possible in Lister/ListerPro)
      Allows the use of OR-groups (not possible in Lister/ListerPro)
      If ListerPro is installed you can run ListerPro actions on the listed pages - the available actions are defined in the module config.
      Bookmarks can be configured in the module config and accessed via the flyout menu for the module page. For your convenience you can copy/paste a bookmark string from the note at the bottom of the Lister Selector results.
      Usage
      Type your selector string on the Selector tab. The selector is applied when the "Selector string" field is blurred, so hit Tab when you have finished typing your selector.
      Unlike Lister/ListerPro, you can't sort results by clicking the column headings. Control the sort within the selector string instead.
      Superusers can jump to the module config (e.g. to create a bookmark) by clicking the cog icon at the top right of the module interface.
      The module is mostly intended for use by superusers, because in most cases site editors won't understand the ProcessWire selector string syntax. If you want another role to be able to access Lister Selector then give the role the "lister-selector" permission. Only superusers can define bookmarks because in ProcessWire module config screens are only accessible to superusers.
      Screenshots
      Process page

      Module config (when ListerPro is installed)

      Advanced
      If for any reason you want to create dynamic bookmark links to Lister Selector for a given selector you can do that like this:
      /** @var $pls ProcessListerSelector */ $pls = $modules->get('ProcessListerSelector'); // Define selector $selector = "template=foo, title%=bar"; // Define columns (optional) $columns = 'title,modified'; $pls_link = $pls->getProcessPage()->url . '?bm=' . $pls->urlSafeBase64Encode($selector . ':' . $columns); echo "<a href='$pls_link'>My link</a>";  
      https://github.com/Toutouwai/ProcessListerSelector
      https://modules.processwire.com/modules/process-lister-selector/
    • By Marvin
      Hello, excuse me
      I'm new at processwire, i want to ask about a master detail system (Inheritance system) using a processwire. Can we create a Inheritance table using a processwire, and how we create it? Thank you for the help
    • By Peter Knight
      Hey I'm building my first new site in well over a year and am a little rusty on selectors but particularly retrieving sub-fields of selected pages.
      I am trying to output the meta data of a blog post as follows.
      [Person Name] is just a field with a Page Reference and simple enough.
      [Job Title] is the sub-field within the page that was referenced above.
      I actually have it working with the following:
      Posted by: <?php if($page->insight_author) { echo $page->insight_author("<a href='{url}'>{title}</a>");} ?> , <?php $roles = $page->insight_author; foreach ($roles as $role) { echo "{$role->staff_role}";} ?> but was wondering how to do this with selector sub-selectors instead. My current code is probably quite 'old school'?
      Thanks
       
    • By Marvin
      Hi,
      I'm still new at processwire, i want to ask, i was create a website with sign in system, but i want to add a access roles/permission for each user at my website. For now, i just can create a login user without any permission and the user data became as a pages in my processwire.
      Here i attach my code for login
      <?php $note = $note2 = $hidden =""; if($input->get->id == "logout") { $session->remove('login_id'); } if($input->post->submit) { $email = $sanitizer->email($input->post->email); $pass = $sanitizer->text($input->post->pass); $result = $pages->find("email=$email, text_1=$pass"); if(!$email || !$pass) { $note = "Data belum lengkap"; } else { if($result->count > 0) { $session->login_id = "$result"; $hidden = "style = 'diplay:none'"; $url=$pages->get("/files/")->httpUrl; header("Location:$url"); die(); } else { $note = "Akun tidak ditemukan"; } } } ?> And this code for login form
      <div class="frow-container"> <div class="frow centered mt-50"> <div class="col-md-1-3"> <div class="box p-40 shadow-light"> <h2 class="mb-20 text-center" <?=$hidden?>>Database Partitur<br>GII HIT</h2> <form method="post" <?=$hidden?>> <label>Username <input type="text" name="email"></label> <label>Password <input type="password" name="pass"></label> <input type="submit" name="submit" value="Masuk"> </form> <p class="notif"><?=$note;?></p> <div class="text-center"><?=$note2;?></div> </div> </div> </div> </div> Just for remember, my user data now is a pages, and i cannot give any permission to user data.
      Thank you very much for help.
×
×
  • Create New...