Free Arcade Script
FAS Customization => Addons/Modifications => V2.x => : Dillon 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
ALTER TABLE dd_users ADD template VARCHAR(250) NOT NULL DEFAULT '';
Open
includes/core.php
search for
$db->connect();
Add this code after
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
$template = $set['template'];
Replace with
if(!empty($user_template) && $user_template != "default"){ $template = $user_template; }else{ $template = $set['template']; }
Open myaccount.php and pages/admin/managemembers.php
search for
$newsletter = clean($_POST['newsletter']);
Add after
$utemplate = clean($_POST['template']);
Search for
newsletter='$newsletter'
Add after
, template='$utemplate'
Search for
------------------------------
myaccount.php file
------------------------------
$newsletter = $r2['newsletter'];
------------------------------
managemembers.php file
------------------------------
$newsletter = $set['newsletter'];
Add after
------------------------------
myaccount.php file
------------------------------
$utemplate = $r2['template'];
------------------------------
managemembers.php file
------------------------------
$utemplate = $set['template'];
Search for
<td class="content"><select type="dropdown" name="newsletter">
<option value="no">No</option>
<option value="yes" '.$nsel.' >Yes</option>
</select>
</td>
</tr>
Add after
<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!
-
You've been busy! I'll have a look at it tomorrow. :P
die() missing ??
-
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!
-
whats the point of moving it? lol
-
Just being tidy - because that's where you have added it to the script.
No other reason! ;D
-
Ah thats kinda what i was thinking. Also, What does die() do? maybe i can work it in there if needed?
-
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?
-
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.
-
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
-
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.
-
Rather than use the die(), better to use an if else fork with an if (query) { code } else { exit() } type of flow.
-
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.
-
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.
-
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
-
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.
-
Are you sure you're not making a rod for your own back - - Because I don't know why you don't wait for the next version to play with as I'm sure Adam would have addressed all the problems with:
The html, nested forms, form errors, nested table errors - The ability to edit file names without going to the Db to do it. And all the other script and html errors. ;)
-
meh im learning at the moment not really caring about the work itself
-
Me too! ;)
-
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.
That's because you are "Guessing" what is in place and what is not, instead of checking that it exists.?
Every template would need a file named the same as the template - like default.cfg in the default, and "black.cfg" for a template named black - for example.
That file would only need to be at the minimum:
<?php
// This file needs to exist
?>
And this is where checking it with a variable takes the guesswork out of it.
If (whatever($template/$template.cfg)) {do this}else{do that};
-
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.
That's because you are "Guessing" what is in place and what is not, instead of checking that it exists.?
Every template would need a file named the same as the template - like default.cfg in the default, and "black.cfg" for a template named black - for example.
That file would only need to be at the minimum:
<?php
// This file needs to exist
?>
And this is where checking it with a variable takes the guesswork out of it.
If (whatever($template/$template.cfg)) {do this}else{do that};
Actually i have redone this in the newest version of the script. It works a bit differently and if i remember correctly i put in a check to make sure it exists and if not it uses default, im not entirely sure because i havnt worked on it in a while because of the holiday.
-
Actually i have redone this in the newest version of the script. It works a bit differently and if i remember correctly i put in a check to make sure it exists and if not it uses default, im not entirely sure because i havnt worked on it in a while because of the holiday.
I suspect that you unbanned me because you would like some help here. So what are all the other "Developers" doing?
I took an interest in what you were trying to do with this because it's something that you have been working on for a long time.
But you don't cache "User Themes", only the Default, because if they change it - They have to wait until the cache refreshes before they can see it. It's the Default that gets the hiding - Not the user-themes. ;)
And if you want to write this in a different way?
<option value="default">default</option>';
$theme = "SELECT * FROM fas_themes WHERE `active`='1'";
$theme = sqlcache('themes', $cachelife, $theme);
foreach($theme as $row2){
if ($row2['name'] == $utemplate) { $usel = "selected"; }else{ $usel = NULL; }
echo"<option value=".$row2['name']." ".$usel." >".$row2['name']."</option>";
}
echo'
</select>
Try something like this.
$query = $db->query(sprintf("SELECT template_name FROM " . THEMES_TABLE . " WHERE visible=1 ORDER BY template_name ASC")) or die(mysql_error());
$style_list = '
<select name="user_style">';
while($row = $db->fetch_row($query)){
$template_name = $row['template_name'] ;
$selected = '';
if (!empty($user_style) && ($template_name == $user_style))
{
$selected = 'selected="selected"';
}
$style_list .= '<option style="width:100px;" value="'.$template_name.'"'.$selected.'>'.$template_name.'</option>';
};
$style_list .= '</select>';
echo '
'.$style_list.'
-
Actually i have redone this in the newest version of the script. It works a bit differently and if i remember correctly i put in a check to make sure it exists and if not it uses default, im not entirely sure because i havnt worked on it in a while because of the holiday.
I suspect that you unbanned me because you would like some help here. So what are all the other "Developers" doing?
I took an interest in what you were trying to do with this because it's something that you have been working on for a long time.
But you don't cache "User Themes", only the Default, because if they change it - They have to wait until the cache refreshes before they can see it. It's the Default that gets the hiding - Not the user-themes. ;)
And if you want to write this in a different way?
<option value="default">default</option>';
$theme = "SELECT * FROM fas_themes WHERE `active`='1'";
$theme = sqlcache('themes', $cachelife, $theme);
foreach($theme as $row2){
if ($row2['name'] == $utemplate) { $usel = "selected"; }else{ $usel = NULL; }
echo"<option value=".$row2['name']." ".$usel." >".$row2['name']."</option>";
}
echo'
</select>
Try something like this.
$query = $db->query(sprintf("SELECT template_name FROM " . THEMES_TABLE . " WHERE visible=1 ORDER BY template_name ASC")) or die(mysql_error());
$style_list = '
<select name="user_style">';
while($row = $db->fetch_row($query)){
$template_name = $row['template_name'] ;
$selected = '';
if (!empty($user_style) && ($template_name == $user_style))
{
$selected = 'selected="selected"';
}
$style_list .= '<option style="width:100px;" value="'.$template_name.'"'.$selected.'>'.$template_name.'</option>';
};
$style_list .= '</select>';
echo '
'.$style_list.'
I'm not really sure what you're trying to say here exactly. I understand parts of it but could you possibly elaborate?
-
I'll explain it a bit later - ;D
With this script, from what I can see - If you change the default style in the ACP to say "Blue" the user will be still be redirected to a theme called default? And if the "default" theme doesn't exist - as it doesn't in beta2 What happens if one is not logged in, or hasn't selected a theme, and the theme "default" doesn't exist?
if(isset($_SESSION['userid'])){
$suserid = $_SESSION['userid'];
$usrdata = $db->fetch_row($db->query(sprintf('SELECT * FROM dd_users WHERE userid=\'%u\'', $suserid)));
}else{
$suserid = NULL;
$usrdata = NULL;
}
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 = '';
}
if(!empty($user_template) && $user_template != "default"){
$template = $user_template;
}else{
$query = mysql_query("SELECT `template` FROM `fas_themes` WHERE `default`='1'");
$row = mysql_fetch_array($query);
$template = $row['template'];
}
-
I'll explain it a bit later - ;D
With this script, from what I can see - If you change the default style in the ACP to say "Blue" the user will be still be redirected to a theme called default? And if the "default" theme doesn't exist - as it doesn't in beta2 What happens if one is not logged in, or hasn't selected a theme, and the theme "default" doesn't exist?
if(isset($_SESSION['userid'])){
$suserid = $_SESSION['userid'];
$usrdata = $db->fetch_row($db->query(sprintf('SELECT * FROM dd_users WHERE userid=\'%u\'', $suserid)));
}else{
$suserid = NULL;
$usrdata = NULL;
}
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 = '';
}
if(!empty($user_template) && $user_template != "default"){
$template = $user_template;
}else{
$query = mysql_query("SELECT `template` FROM `fas_themes` WHERE `default`='1'");
$row = mysql_fetch_array($query);
$template = $row['template'];
}
By default it means the theme that is set as default in the admin panel. There isnt actually supposed to be a theme called "default" it just means to instead of selecting a user set theme it will select the theme that the admins have set to be the default theme.
-
Bit confusing if not anything else?
If you changed the user "template" to "user_template"
You could use something like this.
if(isset($_SESSION['userid'])){
$suserid = $_SESSION['userid'];
$usrdata = $db->fetch_row($db->query(sprintf("SELECT * FROM dd_users WHERE userid='%u'", $suserid)));
$query = mysql_query("SELECT template FROM fas_themes WHERE visible=1 ORDER BY template ASC") or die(mysql_error());
while($row = mysql_fetch_array($query)) {
$available = $row['template'];
$style = $usrdata['user_template'];
if((!$usrdata) || ($available != $style)){$template = $template; // Whatever is set in the ACP Settings
}else{
if(!empty($style)) {$template = $style;}
}
}
mysql_free_result($query);
}
Too easy. :P
-
Bit confusing if not anything else?
If you changed the user "template" to "user_template"
You could use something like this.
if(isset($_SESSION['userid'])){
$suserid = $_SESSION['userid'];
$usrdata = $db->fetch_row($db->query(sprintf("SELECT * FROM dd_users WHERE userid='%u'", $suserid)));
$query = mysql_query("SELECT template FROM fas_themes WHERE visible=1 ORDER BY template ASC") or die(mysql_error());
while($row = mysql_fetch_array($query)) {
$available = $row['template'];
$style = $usrdata['user_template'];
if((!$usrdata) || ($available != $style)){$template = $template; // Whatever is set in the ACP Settings
}else{
if(!empty($style)) {$template = $style;}
}
}
mysql_free_result($query);
}
Too easy. :P
The reason i did it the way i did was so that so if the user never changed their theme and they just left it the one set as default. Then the admin decides that he wants to add a new theme and change that to the default. If i dont have the default option, unless i can think of another way, the users will still stay at the old default theme(unless deleted of course) even though i changed the default theme in the admin panel. Get what im saying?
-
Get what im saying?
No I don't - The "default" theme in the ACP is the one Admin wants the Guests to see - Or "New" users to have when they register - Not force users to have it, just because he thinks they should. Doesn't make sense? :(
-
Get what im saying?
No I don't - The "default" theme in the ACP is the one Admin wants the Guests to see - Or "New" users to have when they register - Not force users to have it, just because he thinks they should. Doesn't make sense? :(
I see what your saying.
-
There's something else that is missing,
Without logged Sessions or Cookie Sessions, I can't see how anything the user selects is going to be "Remembered" from page to page, or how things are going to be "Remembered" between login and logout.
FAS has neither?
-
There's something else that is missing,
Without logged Sessions or Cookie Sessions, I can't see how anything the user selects is going to be "Remembered" from page to page, or how things are going to be "Remembered" between login and logout.
FAS has neither?
The theme they select is saved in the database, im not sure what you mean.
-
Put this at the top of index.php in a new line after the <?php
// Print Cookie vars.
print_r($_COOKIE);
// Print Session vars.
foreach($_SESSION as $key => $value) {
echo 'Current session variable ' . $key . ' is: ' . $value . '<br />';
}
You can't just simply add global user functions to the DB and not include "Their preferences" in SESSIONS or cookies.
It will show you what they have, and then you have to determine what's missing at least in the session, because you don't have cookies.
-
Put this at the top of index.php in a new line after the <?php
// Print Cookie vars.
print_r($_COOKIE);
// Print Session vars.
foreach($_SESSION as $key => $value) {
echo 'Current session variable ' . $key . ' is: ' . $value . '<br />';
}
You can't just simply add global user functions to the DB and not include "Their preferences" in SESSIONS or cookies.
It will show you what they have, and then you have to determine what's missing at least in the session, because you don't have cookies.
Alright thanks i will look into this when im not so busy.