*

Recent

Author Topic: User template setting  (Read 32515 times)

Dillon

  • Developer
  • Sr. Member
  • ******
  • Posts: 340
  • Force: +3/-0
    • Arcade Freak
User template setting
« on: October 27, 2011, 11:14:17 PM »
This mod will allow users to choose which template they want to use if the webmaster has uploaded more than 1 template. If the users template is set to nothing or "default" then it will use the sites default template. *NOTE* that means you can not use default as one of your template names. The only problem i see with this script is that if a user sets their template to "custom" then the webmaster deletes the template "custom" it will no longer allow them to log in until it is changed. I tried to add a check if the directory existed and failed, so if someone wants to help with that then that would be great!

First off run this SQL command in your database

Code: [Select]
ALTER TABLE dd_users ADD template VARCHAR(250) NOT NULL DEFAULT '';

Open
includes/core.php

search for

Code: [Select]
$db->connect();
Add this code after

Code: [Select]
if(isset($_SESSION['userid'])){
$suserid = $_SESSION['userid'];
$usrdata = $db->fetch_row($db->query(sprintf('SELECT * FROM dd_users WHERE userid=\'%u\'', $suserid)));
}

if(isset($suserid)){
$query = mysql_query("SELECT `template` FROM `dd_users` WHERE `userid`='$suserid'");
$row = mysql_fetch_array($query);
$user_template = $row['template'];
}else{
$user_template = '';
}

Search for

Code: [Select]
$template = $set['template'];

Replace with

Code: [Select]
if(!empty($user_template) && $user_template != "default"){ $template = $user_template; }else{ $template = $set['template']; }
Open myaccount.php and pages/admin/managemembers.php

search for

Code: [Select]
$newsletter = clean($_POST['newsletter']);

Add after

Code: [Select]
$utemplate = clean($_POST['template']);

Search for

Code: [Select]
newsletter='$newsletter'

Add after

Code: [Select]
, template='$utemplate'

Search for

Code: [Select]
------------------------------
myaccount.php file
------------------------------
$newsletter = $r2['newsletter'];

------------------------------
managemembers.php file
------------------------------
$newsletter = $set['newsletter'];

Add after

Code: [Select]
------------------------------
myaccount.php file
------------------------------
$utemplate = $r2['template'];

------------------------------
managemembers.php file
------------------------------
$utemplate = $set['template'];

Search for

Code: [Select]
<td class="content"><select type="dropdown" name="newsletter">
<option value="no">No</option>
<option value="yes" '.$nsel.' >Yes</option>
</select>
</td>
</tr>

Add after

Code: [Select]
<tr>
<td class="content">Template:</td>
<td class="content"><select type="dropdown" name="template">
<option value="default">default</option>';
$path = $directorypath."templates";
$directory = dir($path);
while (false !== ($item = $directory->read())) {
if ($item !== "." && $item !== "..") {
if ($item == $utemplate) { $usel = "selected"; }
echo"
<option value=".$item." ".$usel." >".$item."</option>";
}
}
echo'
</select>
</td>
</tr>


Hope you like it! Let me know what you think!

Frank

  • Sr. Member
  • ****
  • Posts: 257
  • Force: +4/-0
Re: User template setting
« Reply #1 on: October 28, 2011, 07:22:56 AM »
You've been busy! I'll have a look at it tomorrow. :P

die() missing ??

Frank

  • Sr. Member
  • ****
  • Posts: 257
  • Force: +4/-0
Re: User template setting
« Reply #2 on: October 29, 2011, 04:02:05 AM »
There's got to be a better way to slice bread - But I'm sure you'll work it out. :)

Install:

ALTER TABLE `dd_users` ADD `template` VARCHAR(250) NOT NULL DEFAULT '' AFTER `newsletter`;

Uninstall:
ALTER TABLE `dd_users` DROP template;

Lol!

Dillon

  • Developer
  • Sr. Member
  • ******
  • Posts: 340
  • Force: +3/-0
    • Arcade Freak
Re: User template setting
« Reply #3 on: October 29, 2011, 01:05:05 PM »
whats the point of moving it? lol

Frank

  • Sr. Member
  • ****
  • Posts: 257
  • Force: +4/-0
Re: User template setting
« Reply #4 on: October 29, 2011, 08:44:15 PM »
Just being tidy - because that's where you have added it to the script.

No other reason! ;D

Dillon

  • Developer
  • Sr. Member
  • ******
  • Posts: 340
  • Force: +3/-0
    • Arcade Freak
Re: User template setting
« Reply #5 on: October 30, 2011, 10:49:44 AM »
Ah thats kinda what i was thinking. Also, What does die() do? maybe i can work it in there if needed?

soulwebsites

  • Jr. Member
  • **
  • Posts: 71
  • Force: +0/-0
    • Jamsite
Re: User template setting
« Reply #6 on: October 30, 2011, 11:44:08 AM »
I am currently working out the errors on my site before adding any more mods but this is something i would like.

as an idea is it possible to add a auto theme so if its someones birthday or Christmas etc it changes the theme?

Adam LaCombe

  • Sr. Member
  • ****
  • Posts: 433
  • Force: +17/-0
    • My Blog
Re: User template setting
« Reply #7 on: October 30, 2011, 02:53:11 PM »
Code: [Select]
if(!empty($user_template) && $user_template != "default"){ $template = $user_template; }else{ $template = $set['template']; }
if(((date('m') == 12) && (date('d') == 25)){ $template = "christmas"; }

Same thing for birthday basically. Just check to make sure they're logged in then get their birthday from a mysql query and check it using a if statement to see if today  = the users birthday just like I did above ^^ and if so then $template for them = birthday template.

Frank

  • Sr. Member
  • ****
  • Posts: 257
  • Force: +4/-0
Re: User template setting
« Reply #8 on: October 30, 2011, 04:30:55 PM »
Also, What does die() do? maybe i can work it in there if needed?

It's not IF, it's it should be there to escape a bad query and send an error message.

http://www.roseindia.net/sql/mysql-example/php-sql-die.shtml

Adam LaCombe

  • Sr. Member
  • ****
  • Posts: 433
  • Force: +17/-0
    • My Blog
Re: User template setting
« Reply #9 on: October 30, 2011, 07:55:38 PM »
but if you're going to use die on a mysql query, don't use mysql_error() if your website is public. Only use mysql_error() when editing your website privately.
Any query errors showing up will display the query or the section of the query that is bad.. so that can show a potential hacker just the right information he needs to hack into a user account or whatever really.

kurt

  • Developer
  • Hero Member
  • ******
  • Posts: 634
  • Force: +16/-1
Re: User template setting
« Reply #10 on: November 06, 2011, 06:02:59 PM »
Rather than use the die(), better to use an if else fork with an if (query) { code } else { exit() } type of flow.

Dillon

  • Developer
  • Sr. Member
  • ******
  • Posts: 340
  • Force: +3/-0
    • Arcade Freak
Re: User template setting
« Reply #11 on: November 06, 2011, 06:17:23 PM »
Ok ill look into it later. Im trying to make my site error free and i am removing most of the code from the templates and making them functions so i havnt been working on the mods as much lately.... well unless of course one of the mods was causing the errors.

Dillon

  • Developer
  • Sr. Member
  • ******
  • Posts: 340
  • Force: +3/-0
    • Arcade Freak
Re: User template setting
« Reply #12 on: November 11, 2011, 09:59:10 PM »
So after im done fixing my site, im going to add checks for more errors and also im thinking about restructuring this making it so that the admin settings read all the folders instead of the user settings and allow the admin to activate or deactivate a template.

Frank

  • Sr. Member
  • ****
  • Posts: 257
  • Force: +4/-0
Re: User template setting
« Reply #13 on: November 12, 2011, 10:46:51 PM »
And allow the admin to activate or deactivate a template.

That's more like what CMS does - Here's one you can practice with - It does all that and more? :)

http://icyphoenix.com

Dillon

  • Developer
  • Sr. Member
  • ******
  • Posts: 340
  • Force: +3/-0
    • Arcade Freak
Re: User template setting
« Reply #14 on: November 13, 2011, 10:16:45 AM »
yes thats based off of phpbb which is what i use on my other website and thats what i was getting this idea from however i have not looked into how theyve done it but rather iv come up with my own idea im going to try and get working.