LukeCage

Admin Custom Page and Registration

Recommended Posts

Hi! I have a big problem with a client of mine. I have to do something that i don't do very often with processwire, and i'm very afraid that i'm not gonna able to do it. So i write to search some help from you experts.

The website that i'm gonna create will have a database with infos about users. This users are not the actual registrered users, but possible users. I'll try my best to explain this. What i will have is a datasheet in the database with infos about all the users (name, surname, fiscal Code) that can register to the website. So during registration the website is confront with this database of people, and accept or not your registration to the website.

Now. The problems are: the client need a page in the CMS to insert this people in the first place (Custom Admin Page?) in the database. I read what i need to create it, but i don't understand what i need to do next. What i need to do for reading and writing to the database, with data, directly from a custom admin page in processwire?

The other thing is. I can do this control during registration? I Can extend fields in the user account?

I'm completely in your hands.

Share this post


Link to post
Share on other sites
2 hours ago, LukeCage said:

The problems are: the client need a page in the CMS to insert this people in the first place

  1. Is the client going to type in the data one by one or are you importing from a file, .e.g a CSV or JSON file?
  2. How many people potentially in the datasheet?
  3. Will this be done once or will the people be regularly updated?
  4. Can the people be saved as pages (hidden in admin) or you'd rather have them in a table external to ProcessWire?

Manage People Datasheet

You might need to create a simple Process Module, maybe even a one pager that lists the 'people'. You can include some simple actions like delete or edit people. To add people, a click on some button could open a modal window for you to add a person (depends on whether you are importing a file of people or typing manually).

There's also the module RockGrid that you can use for listing the 'people'. I don't know if it can do data imports though. I think it works with ProcessWire pages only, but am not sure.

User registration

Since creating users is a manual process, you have a lot of control here. How you check if a user is on the allowed people list depends on the approach you take above, i.e. whether people are pages or are in a custom database. If they are pages, you can use $pages API, e.g. $newUser = $pages->get("template=people, first_name=$firstName,last_name=$lastName"); Then check if that returned something. If yes, register this user. If you are using a custom table, you'd need to use SQL to fetch, insert, update, etc, people. ProcessWire has a $database API that you can use

Your other option is a custom Fieldtype but that is a bit more technical, going by how you've described your current skill set. 

2 hours ago, LukeCage said:

i'm very afraid that i'm not gonna able to do it. So i write to search some help from you experts.

Depending on your timescales, you might be able to get some help in the forums. If this is needed fairly soon, you might want to consider hiring an experienced ProcessWire developer to carry out the work for you.

  • Like 2

Share this post


Link to post
Share on other sites
6 hours ago, kongondo said:
  1. Is the client going to type in the data one by one or are you importing from a file, .e.g a CSV or JSON file?
  2. How many people potentially in the datasheet?
  3. Will this be done once or will the people be regularly updated?
  4. Can the people be saved as pages (hidden in admin) or you'd rather have them in a table external to ProcessWire?

Manage People Datasheet

You might need to create a simple Process Module, maybe even a one pager that lists the 'people'. You can include some simple actions like delete or edit people. To add people, a click on some button could open a modal window for you to add a person (depends on whether you are importing a file of people or typing manually).

There's also the module RockGrid that you can use for listing the 'people'. I don't know if it can do data imports though. I think it works with ProcessWire pages only, but am not sure.

User registration

Since creating users is a manual process, you have a lot of control here. How you check if a user is on the allowed people list depends on the approach you take above, i.e. whether people are pages or are in a custom database. If they are pages, you can use $pages API, e.g. $newUser = $pages->get("template=people, first_name=$firstName,last_name=$lastName"); Then check if that returned something. If yes, register this user. If you are using a custom table, you'd need to use SQL to fetch, insert, update, etc, people. ProcessWire has a $database API that you can use

Your other option is a custom Fieldtype but that is a bit more technical, going by how you've described your current skill set. 

Depending on your timescales, you might be able to get some help in the forums. If this is needed fairly soon, you might want to consider hiring an experienced ProcessWire developer to carry out the work for you.

1- the idea was that the client update this list. The option that imports from a csv is an option but can be very handy. What I know is that the interest is to export in a csv registered user and other lists. So I a do people as pages, I can export an hidden category with lots of pages in a csv? 

2- The people's list are very very large. Actually there's a database in the old website that I need to import in the first place. 

3- will be regularly updated once or twice a year, maybe more. 

4- No the people can be pages. The peoples are gonna store in the same database, so the important thing is to have a tab in the admin, so can be easy to the client to see only the people, and not all the pages etc.. I want to create a tab because I think that the page tree, with all the names, are gonna be very large, and not very easy to read.

Edited by LukeCage
  • Like 1

Share this post


Link to post
Share on other sites

I would go with a custom module to give ability to your administrators to insert/remove/update the potentials users which ares stored in the pages tree.  If the people pages list is very large, it is not a problem, you will end up with a paginated pages tree, and you will have the ability to find easily those users (pages) from the search case or even the Pages  > Find menu. You can also write a small Process module to manage those pages with a datatable, rockgrid or whatever you would like to use.

-

Reading @kongondo's answer after writing I see that he already explained the idea.

 

4 hours ago, LukeCage said:

I can export an hidden category with lots of pages in a csv?

Check this thread.

4 hours ago, LukeCage said:

The people's list are very very large. Actually there's a database in the old website that I need to import in the first place. 

Simply build a template for "people" and import them as a pages. 

4 hours ago, LukeCage said:

No the people can be pages.

This make things a lot easier. Just build your Process module to manage those pages. You can have a working prototype at the end of the day with all the information found on this forum.

  • Like 3

Share this post


Link to post
Share on other sites

Yeah, what @flydev said. Pages is the easier route in your case. We are not saying it cannot be done by using your custom database and querying it directly. That's possible, but in your case, a lot more technical work.

Your client does not have to see the tree of people pages. You can have those hidden under a single parent whose parent is /admin/ rather than home (/). This way, only superusers can see the people tree. With a Process Module, you don't have to be visiting the page tree even as a superuser. You only need to know that they are there and the evidence is that you can see them in your Process Module :-).

The 'each person is a page' approach means that ProcessWire does all the heavy lifting, dealing with databases operations. Heck, your Process Module will allow you to filter users or sort them according to some column. Your database columns, depending on the data, can either be stored as single ProcessWire fields - name=text;surname=text,other_data=integer, etc OR as one blob of JSON text in a single text field, which can be retrieved and turned into an array. We need to see the column names and how many you got, to give a definite answer.

How has your client been updating the database in the old website? 

You still haven't told us how soon you need this 🙂

 

  • Like 1

Share this post


Link to post
Share on other sites
1 hour ago, kongondo said:

Yeah, what @flydev said. Pages is the easier route in your case. We are not saying it cannot be done by using your custom database and querying it directly. That's possible, but in your case, a lot more technical work.

Your client does not have to see the tree of people pages. You can have those hidden under a single parent whose parent is /admin/ rather than home (/). This way, only superusers can see the people tree. With a Process Module, you don't have to be visiting the page tree even as a superuser. You only need to know that they are there and the evidence is that you can see them in your Process Module :-).

The 'each person is a page' approach means that ProcessWire does all the heavy lifting, dealing with databases operations. Heck, your Process Module will allow you to filter users or sort them according to some column. Your database columns, depending on the data, can either be stored as single ProcessWire fields - name=text;surname=text,other_data=integer, etc OR as one blob of JSON text in a single text field, which can be retrieved and turned into an array. We need to see the column names and how many you got, to give a definite answer.

How has your client been updating the database in the old website?

You still haven't told us how soon you need this 🙂

 

They write to csv, then they send this to the developer. But after i said them they were absolutely doing this directly from the website, they were absolutely enthusiastic.

My question is: I have read how to do a module in the Admin (it is very easy to create it), but how i can display the pages only in that new tab? Like an html table or something similar? And maybe in all of those, insert the modify button (that redirect to the normal page edit). Technically i never do this, and i don't know where to start.

Share this post


Link to post
Share on other sites
1 hour ago, LukeCage said:

My question is: I have read how to do a module in the Admin (it is very easy to create it), but how i can display the pages only in that new tab? Like an html table or something similar? And maybe in all of those, insert the modify button (that redirect to the normal page edit). Technically i never do this, and i don't know where to start.

Luke, the reason am asking particular questions is so that we can offer a tailored response. Without more information, it is difficult to offer a specific answer. For instance, I asked, how many columns in the database? But it seems to me you now want to go with pages, as per our suggestion, right?

Assuming you are going with pages. 

Display

Your process module, in its execute function (I am assuming you've read about this?) will render your HTML table. You can either render a ProcessWire table, or your own custom HTML table, or use Process Lister or RockGrid. All of this can be paginated so that only a limited number of people are loaded at a time. See Process Blog module for displaying pages in a HTML table.

In the HTML table, do you want to display all data columns (e.g. name, surname, fiscal thingy, etc) OR do you want to display only full name (i.e. Steve Job?)

Modal

  • Then when client clicks on Steve Job, it opens a modal to the Steve Job page.
  • The Steve Job page has several fields for name, surname, fiscal thing, etc.
  • The client edits the fields he wants and closes the modal
  • The page reloads (or if using ajax, only the data reloads)
  • See Blog module (Process blog for opening pages in modal for editing)

Note: Since the pages are in admin, we will have to by-pass user access check in order for client to edit the page

Uploading new 'people'

  • We have a button or file field for uploading new people data as CSV (see my FieldtypeMatrix module for example)
  • When the csv file is uploaded, a script loops through it and creates people pages on the fly, mapping csv columns data to the ProcessWire page's fields. Before creating a page we check if there is already a people page with similar data {same email, same name, same surname, etc}
  • You then decide what you need to do; update if duplicate found or skip creation of that people page?
  • People page reloads (or ajax refresh)

These are ideas, but very doable. But we need specific answers to our questions. You never know; someone might just create a draft module for you 🙂

Edited by kongondo
  • Like 2

Share this post


Link to post
Share on other sites
31 minutes ago, kongondo said:

Luke, the reason am asking particular questions is so that we can offer a tailored response. Without more information, it is difficult to offer a specific answer. For instance, I asked, how many columns in the database? But it seems to me you now want to go with pages, as per our suggestion, right?

Assuming you are going with pages.

Display

Your process module, in its execute function (I am assuming you've read about this?) will render your HTML table. You can either render a ProcessWire table, or your own custom HTML table, or use Process Lister or RockGrid. All of this can be paginated so that only a limited number of people are loaded at a time. See Process Blog module for displaying pages in a HTML table.

In the HTML table, do you want to display all data columns (e.g. name, surname, fiscal thingy, etc) OR do you want to display only full name (i.e. Steve Job?)

Modal

  • Then when client clicks on Steve Job, it opens a modal to the Steve Job page.
  • The Steve Job page has several fields for name, surname, fiscal thing, etc.
  • The client edits the fields he wants and closes the modal
  • The page reloads (or if using ajax, only the data reloads)
  • See Blog module (Process blog for opening pages in modal for editing)

Note: Since the pages are in admin, we will have to by-pass user access check in order for client to edit the page

Uploading new 'people'

  • We have a button or file field for uploading new people data as CSV (see my FieldtypeMatrix module for example)
  • When the csv file is uploaded, a script loops through it and creates people pages on the fly, mapping csv columns data to the ProcessWire page's fields. Before creating a page we check if there is already a people page with similar data {same email, same name, same surname, etc}
  • You then decide what you need to do; update if duplicate found or skip creation of that people page?
  • People page reloads (or ajax refresh)

These are ideas, but very doable. But we need specific answers to our questions. You never know; someone might just create a draft module for you 🙂

That's exactly what i want to do. The info are gonna be more than six or seven "fields" per person.

What i haven't done before is importing with csv and transform to pages, i have to dig more into this.

How can i display a ProcessWire table in excecute() ? I can not understand how to do that...

Share this post


Link to post
Share on other sites

Here's something to chew on.

Start with this tutorial: https://processwire.com/blog/posts/building-custom-admin-pages-with-process-modules/

Some code to play with. This creates a paginated ProcessWire-rendered HTML table.

  • Create a module as per above tutorial.
  • Use the following code in your Process module's execute() method.
  • You need to create some people pages. In this example, they use the template 'people'.
  • Edit functionality not included. Have a look at Blog module for that, here.
  • For CSV upload (not included), have a look at Matrix module here for uploading CSV file and here for reading CSV file.

 

/**
 *	Display, Add and Edit People.
 *
 *	Called when the URL is peoples's page URL + "/people/" i.e. URL Segment.
 *	Renders a table with People information. People can be edited via modal.
 *
 *	@access protected
 *	@return mixed $form rendered form
 *
 */
public function ___execute() {

    $modules = $this->wire('modules');
    $input = $this->wire('input')->post;
    $pages = $this->wire('pages');

    // CREATE A NEW FORM
    $form = $modules->get('InputfieldForm');
    $form->attr('id', 'people');
    $form->action = './';
    $form->method = 'post';

    // CREATE AN INPUTFIELD MARKUP: Will hold list of people table
    $m = $modules->get('InputfieldMarkup');
    $m->textFormat = Inputfield::textFormatNone;// make sure ProcessWire renders custom HTML
    // $m->label = $this->_('Edit');
    // $m->description = $this->_('Click on a title to edit the item.');

    // CREATE A NEW TABLE: for people
    $t = $modules->get('MarkupAdminDataTable');
    $t->setEncodeEntities(false);
    $t->setClass('peopleTable');

    // set header rows
    $peopleTableHeaders = array(
        '<input type="checkbox" class="toggle_all">',
        $this->_('Title'),
        $this->_('Name'),
        $this->_('Surname'),
        $this->_('Another Column'),
        $this->_('One More Column'),
        $this->_('Published'),
        #$this->_('Date'),
    );


    $t->headerRow($peopleTableHeaders);

    // grab a limited number of people to show in people dashboard. Limit is hardcoded in this example
    $people = $pages->find("template=people, include=all, sort=-created, parent!=7, limit=10");

    foreach ($people as $p) {
        if (!count($people)) break;// if no people found, break early
        // check if person page  is published or not
        $p->is(Page::statusUnpublished) ? $status = '<span class="unpublished">' . $this->_('No') . '</span>' : $status = $this->_('Yes');
        // set table rows
        $peopleTable = array(
            "<input type='checkbox' name='posts_action[]' value='{$p->id}' class='toggle'>",// disabled sorting on this in .js file
            "<a href='{$this->wire('config')->urls->admin}page/edit/?id={$p->id}&modal=1' class='editPeople pw-modal pw-modal-medium'>$p->title</a>",
            $p->title,
            $p->person_name,
            $p->person_surname,
            $p->another_column,
            $p->one_more_column,
            $status
        );

        // render the table rows with variables set above
        $t->row($peopleTable);

    }// end foreach $people as $p

    // display a headline indicating quantities. We'll add this to people dashboard
    $start = $people->getStart()+1;
    $end = $start + count($people)-1;
    $total = $people->getTotal();

    if($total) $peopleCount = "<h4>" . sprintf(__('People %1$d to %2$d of %3$d'), $start, $end, $total) . "</h4>";

    // add a description to people dashboard {postsCount, limitSelect and instruction OR no people found status}
    $m->description = $total == 0 ? $this->_('No items found.') : $peopleCount . $this->_('Click on a title to edit the item.');
    $m->notes = "People table notes";

    $currentUrl = $this->wire('page')->url . $this->wire('input')->urlSegmentsStr."/";// get the url segment string. In this case it is "people"
    $pagination = $people->renderPager(array('baseUrl' => $currentUrl));

    $m->attr('value', $pagination . $t->render() . $pagination);// wrap our table with pagination

    $form->add($m);

    $post = $this->wire('input')->post;

    // render the final form
    return $form->render();

}

 

Edited by kongondo
  • Like 5

Share this post


Link to post
Share on other sites
8 hours ago, LukeCage said:

The people's list are very very large

What is "very very large" ?

 

4 hours ago, flydev said:

You can also write a small Process module to manage those pages with a datatable, rockgrid or whatever you would like to use.

3 hours ago, LukeCage said:

My question is: I have read how to do a module in the Admin (it is very easy to create it), but how i can display the pages only in that new tab? Like an html table or something similar? And maybe in all of those, insert the modify button (that redirect to the normal page edit). Technically i never do this, and i don't know where to start.

1 hour ago, LukeCage said:

How can i display a ProcessWire table in excecute() ? I can not understand how to do that...

RockGrid, RockGrid, RockGrid! It's a perfect szenario for it and it was mentioned several times already by @kongondo and @flydev - it seems you didn't have a look yet?

 

8 hours ago, LukeCage said:

The option that imports from a csv is an option but can be very handy. What I know is that the interest is to export in a csv registered user and other lists. So I a do people as pages, I can export an hidden category with lots of pages in a csv? 

There are several modules to help you with CSV import: https://www.google.com/search?q=site:processwire.com+import+csv

 

  • Like 2

Share this post


Link to post
Share on other sites

Forgot one:

8 hours ago, LukeCage said:

What I know is that the interest is to export in a csv registered user and other lists. So I a do people as pages, I can export an hidden category with lots of pages in a csv?

One click with RockGrid, already built in - and they can even filter the grid before exporting 😉

  • Like 1

Share this post


Link to post
Share on other sites
6 minutes ago, bernhard said:

One click with RockGrid, already built in - and they can even filter the grid before exporting 

Awesome! I really need to get some time to test it!

This topic should be marked as [almost solved], eh? ;-). Read @bernhard tutorial on Process Modules and use his RockGrid module 🙂

  • Like 3

Share this post


Link to post
Share on other sites
7 minutes ago, bernhard said:

Forgot one:

One click with RockGrid, already built in - and they can even filter the grid before exporting 😉

Just now, kongondo said:

Awesome! I really need to get some time to test it!

This topic should be marked as [almost solved], eh? ;-). Read @bernhard tutorial on Process Modules and use his RockGrid module 🙂

I will try this first. If is not gonna work form i will go for @kongondo solution.

Next few days i will start programming, and I will let you know how it went!

Share this post


Link to post
Share on other sites
2 minutes ago, kongondo said:

Awesome! I really need to get some time to test it!

You should really do that as soon as possible 😉 I'm using it on all my projects and it's an absolutely awesome listing tool. Much better than the core listing in most of the cases IMHO (not praising my own work here, most of the awesomeness comes from agGrid).

I decided to make it free (MIT) so that others can use it in their modules (batch child editor, the new padloper, etc. - really a lot of possibilities here). I really think that it opens up a new world for processwire regarding how users can manage their content (GUI). 

4 minutes ago, LukeCage said:

Next few days i will start programming, and I will let you know how it went!

Great, good luck and have fun 😉

  • Like 1

Share this post


Link to post
Share on other sites
2 hours ago, bernhard said:
11 hours ago, LukeCage said:

The people's list are very very large

What is "very very large" ?

?

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By mjut
      Hello!
      I am trying to get some extra css-file into my admin templates. I managed to modify my admin.php to this:
      <?php namespace ProcessWire; require($config->paths->adminTemplates . 'controller.php'); echo "<link rel='stylesheet' type='text/css' href='" . $config->urls->templates . "css/admin.css'>"; By doing so, the css <link> is added to the very end of each parsed admin-html. (right AFTER the closing </body> tag.)
      That causes some trouble. e.g. the page tree is not displaying any more. Although, other pages are working - like the edit form of a page.
      My question: is there a correct way of adding my extra css to the admin area?
      Thanks for you help!
      Stephan
       
    • By Robin S
      Breadcrumb Dropdowns
      Adds dropdown menus of page edit links to the breadcrumbs in Page Edit.

      Installation
      Install the Breadcrumb Dropdowns module. The module requires ProcessWire >= v3.0.83 and AdminThemeUikit.
      There is a checkbox option in the module config that determines if the breadcrumb dropdowns will include pages that the user does not have permission to edit.
      Features/details
      The module adds an additional breadcrumb item at the end for the currently edited page. That's because I think it's more intuitive for the dropdown under each breadcrumb item to show the item's sibling pages rather than the item's child pages. In the dropdown menus the current page and the current page's parents are highlighted in a crimson colour to make it easier to quickly locate them in case you want to edit the next or previous sibling page. Unpublished and hidden pages are indicated in the dropdowns with similar styling to that used in Page List. If the option to include uneditable pages is selected then those pages are indicated by italics with a reduced text opacity and the "not-allowed" cursor is shown on hover. There is a limit of 25 pages per dropdown for performance reasons and to avoid the dropdown becoming unwieldy. If the current user is allowed to add new pages under the parent page an "Add New" link is shown at the bottom of the breadcrumb dropdown. If the currently edited page has children or the user may add children, a caret at the end of the breadcrumbs reveals a dropdown of up to the first 25 children and/or an "Add New" link. Overriding the listed siblings for a page
      If you want to override the siblings that are listed in the dropdowns you can hook the BreadcrumbDropdowns::getSiblingsmethod and change the returned PageArray. For most use cases this won't be necessary.
      Incompatibilities
      This module replaces the AdminThemeUikit::renderBreadcrumbs method so will potentially be incompatible with other modules that hook the same method.
       
      https://modules.processwire.com/modules/breadcrumb-dropdowns/
      https://github.com/Toutouwai/BreadcrumbDropdowns
    • By Thomas Diroll
      Hi guys I'm relatively new to PW and just finished developing a page for a client. I was able to include all necessary functionality using the core fieldtypes but now I it seems that I need to extend them with a custom one. What I need is a simple button, that copies the absolute url (frontend not PW-backend) of the page which is currently edited to the clipboard. As this feature is only needed inside a specific template, I tend to use a custom fieldtype which provides this feature. I've been looking inside the core modules code (eg. FieldtypeCheckbox.module) but I don't really get the structure of it and how its rendered to the admin page. I also didn't find a lot of tutorials covering custom fieldtypes.
      Maybe some of you could give me some tips on how to write a basic custom fieldtype that renders a button which copies the value of
      page->httpUrl() to the clipboard using JS. Thanks!
    • By Jacek
      I'm coding my first module now. I've just managed to add a button to the page edit form but am not content with its placing. Is there any way to place it just next to the input field? I've marked the desired place with the arrow on the attached screenshot.
      My current code:
      $this->addHookAfter('ProcessPageEdit::buildFormContent' , $this, 'addButton');
      public function addButton($event){
      $form = $event->return;
      $f =$this->modules->InputfieldSubmit;
      ...
      $form->insertAfter($f, $form->get("bgg_id"));
      }
      "bgg_id" is the name of the targeted field.
       

    • By Noel Boss
      Admin Theme Boss
      A light and clear theme based on Uikit 3
      Features
      Three unique color options Beautiful typografy using Roboto Condensed Extended breadcrumb with edit links Extends AdminThemeUikit, you can continue using all AdminThemeUikit features Option to activate theme for all users Color Variants:
      ProcessWire Blue

      Vibrant Blue

      Dark Black

      Requirements
      Requires AdminThemeUikit installed and activated.
      Installation
      Make sure the above requirements are met Go to “Modules > Site > Add New“ Paste the Module Class Name “AdminThemeBoss“ into the field “Add Module From Directory“ Click “Download And Install“ On the overview, click “Download And Install“ again On the following screen, click “Install Now“

      Install manually
      Make sure the above requirements are met Download the theme files from GitHub or the ProcessWire Modules Repository. Copy all of the files for this module into /site/modules/AdminThemeBoss/ Go to “Modules > Refresh” in your admin Click “Install“ on the “AdminThemeBoss“ Module