This topic is locked
[SOLVED]

 Bootstrap Theme selector

2/6/2017 6:17:38 PM
PHPRunner General questions
W
WilliamB authorDevClub member

Hello,
I was curious if anyone has implemented something like this. I would like to allow users to select there own bootstrap theme. The setting could then be stored in the database. I found a this link that is close to what I want but it does not store settings in database.
Can anyone help on this? Or is Phprunner bringing a setting like this?
Thanks,
Billy

romaldus 2/7/2017

This is very easy.

  1. Create a new table in your database, for example: "theme_list"

    Inside theme_list table, create one field: "themes"

    Now, add the following records to themes field:

cyborg

darkly

default

flatly

journal

lumen

paper

readable

sandstone

simplex

slate

spacelab

superhero

united

yeti

bootstrap

cerulean

cosmo


The above theme list are theme folder names in C:\Program Files\PHPRunner9.6\styles\bootstrap


2. Create one more table in your database, for example: "theme_chooser"

Inside theme_chooser table, create two field: "theme" and "status"
In Phprunner visual editor, setup the "theme" field to lookup from "theme_list" to choose one theme you want

Make sure there is ONLY ONE THEME with "status" ACTIVE in this table
3. In PHPRunner event (After Application Initialized event) add the following code

$sql = "SELECT theme AS mytheme FROM theme_chooser WHERE status = 'ACTIVE'";

$rs = CustomQuery($sql);

$data = db_fetch_array($rs);

$_SESSION["MyCoolTheme"] = $data["mytheme"];


4. Copy All bootstrap styles from C:\Program Files\PHPRunner9.6\styles\bootstrap to /yourwebroot/styles/bootstrap
5. Save your project and .

  • Navigate to : [color="#0000ff"]C:\Program Files\PHPRunner9.6\source\include
  • Open file layoutbuilder.php in your text editor (make sure you backup the original copy of this file)
  • In Line 50, you can find this code $layout->bootstrapTheme = "##@layoutInfo.bootstrapTheme##";



  • Modify the code to $layout->bootstrapTheme = $_SESSION["MyCoolTheme"];



  • Save and close the file
  • Now open phprunner, and generate your project
  • Done <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=81292&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />

romaldus 2/7/2017

sample result :


After Choosing Carulean theme :

W
WilliamB authorDevClub member 2/7/2017

Wow that was quick!
Thank you romaldus. This is exactly what I am looking for. I will try to implement your way tonight! I will need to change it so that each user can pick their own theme.
Billy

mbintex 2/7/2017

just a great input. Thanks.

jadachDevClub member 2/7/2017

That is awesome!!! Thank you.

W
WilliamB authorDevClub member 2/7/2017

I have used your suggestion and instead of using a new table I used the login table and added a columm for the theme as a lookup field
I used this as my After Application Initialized event

//Theme selector

$sql = "SELECT MyTheme FROM tEmployees WHERE strEmpName='".$_SESSION["UserID"]."'";

$rs = CustomQuery($sql);

$data = db_fetch_array($rs);

$_SESSION["MyTheme"] = $data["MyTheme"];


I have a "My Settings" area that the users can modify their settings. I add a refresh after the inline edit.



this.on('afterInlineEdit', function( fieldsData ) {

location.reload();

} )


Now the theme is visible right away.
This works perfectly!
Billy

T
thudsen 2/8/2017
need2sleepDevClub member 2/9/2017

Thank you!
I feel this should be implemented already.



This is very easy.

  1. Create a new table in your database, for example: "theme_list"

    Inside theme_list table, create one field, for example: "themes"

    Now, add the following records to themes field:

cyborg

darkly

default

flatly

journal

lumen

paper

readable

sandstone

simplex

slate

spacelab

superhero

united

yeti

bootstrap

cerulean

cosmo


The above theme list are theme folder names in C:\Program Files\PHPRunner9.6\styles\bootstrap


2. Create one more table in your database, for example: "theme_chooser"

Inside theme_chooser table, create two field: "theme" and "status"
In Phprunner visual editor, setup the "theme" field to lookup from "theme_list" to choose one theme you want

Make sure there is ONLY ONE THEME with "status" ACTIVE in this table
3. In PHPRunner event (After Application Initialized event) add the following code

$sql = "SELECT theme AS mytheme FROM theme_chooser WHERE status = 'ACTIVE'";

$rs = CustomQuery($sql);

$data = db_fetch_array($rs);

$_SESSION["MyCoolTheme"] = $data["mytheme"];


4. Copy All bootstrap styles from C:\Program Files\PHPRunner9.6\styles\bootstrap to /yourwebroot/styles/bootstrap
5. Save your project and .

  • Navigate to : [color="#0000ff"]C:\Program Files\PHPRunner9.6\source\include
  • Open file layoutbuilder.php in your text editor (make sure you backup the original copy of this file)
  • In Line 50, you can find this code $layout->bootstrapTheme = "##@layoutInfo.bootstrapTheme##";



  • Modify the code to $layout->bootstrapTheme = $_SESSION["MyCoolTheme"];



  • Save and close the file
  • Now open phprunner, and generate your project
  • Done <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=81305&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />

John Rotella 2/16/2017

Thank you very much.