Author Topic: style switch by time  (Read 7568 times)

0 Members and 1 Guest are viewing this topic.

Offline marcus_s

  • Newbie
  • *
  • Posts: 33
    • View Profile
style switch by time
« on: April 14, 2005, 09:21:38 PM »
hi. i like to switch the background color and other things in 4images to bright and dark by daytime (day & night).

i got this:

Code: [Select]
<?php
 $hour 
date(G);
 
 if (
$hour && $hour <= 20) { // von vier bis sechs
          include "tag.inc";
 } else if (
$hour 20 || $hour <= 7)  // zwischen 21 und vier
          include "nacht.inc";
 }
?>

that isn´t possible.


i got these error messages:


Warning: Unknown(nacht.inc): failed to open stream: No such file or directory in /…/gallery/includes/template.php(101) : eval()'d code on line 37

Warning: Unknown(nacht.inc): failed to open stream: No such file or directory in /…/gallery/includes/template.php(101) : eval()'d code on line 37

Warning: (null)(): Failed opening 'nacht.inc' for inclusion (include_path='.:/usr/lib/php') in /…/gallery/includes/template.php(101) : eval()'d code on line 37



what do i have to do to make it work?

thanks,

marcus

Offline marcus_s

  • Newbie
  • *
  • Posts: 33
    • View Profile
Re: style switch by time
« Reply #1 on: April 14, 2005, 09:23:27 PM »
oh. found this now:

http://www.4homepages.de/forum/index.php?topic=4295.0

gonna try it first.

marcus

Offline Chris

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 4.487
  • Did u ever stop to think and then forget to start?
    • View Profile
Re: style switch by time
« Reply #2 on: April 14, 2005, 10:12:03 PM »
The code you posted will switch it based on the server's time and not the visitor.  Someone half a world away sitting at their computer in full daylight will see a night theme...

Offline marcus_s

  • Newbie
  • *
  • Posts: 33
    • View Profile
Re: style switch by time
« Reply #3 on: April 14, 2005, 11:09:15 PM »
yea i know but thats ok. my client clients are mostly german.

but im thinking about a javascript solution but i think that i need a php-script because i got some javascript-code to parse (browser-selecion). don´t think that thats gonna work with java … er  8O



the php-script wont work anyway (http://www.4homepages.de/forum/index.php?topic=4295.0) - now i got 5 error messages.

any clues?

thank you, marcus

Offline Chris

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 4.487
  • Did u ever stop to think and then forget to start?
    • View Profile
Re: style switch by time
« Reply #4 on: April 15, 2005, 02:33:03 AM »
Open global.php and locate this code:
Code: [Select]
//-----------------------------------------------------
//--- Generate Setting --------------------------------
//-----------------------------------------------------
$sql = "SELECT setting_name, setting_value
        FROM ".SETTINGS_TABLE;
$result = $site_db->query($sql);
if (!$result) {
  echo $lang['no_settings'];
  exit;
}
while ($row = $site_db->fetch_array($result)) {
  $config[$row['setting_name']] = $row['setting_value'];
}
$site_db->free_result();

Add after it:
Code: [Select]

$hour = date("G");
if( $hour > 7 && $hour <= 20 )
  $config['template_dir'] = "day_template";
else
  $config['template_dir'] = "night_template";

Where day_template is the name of the template directory that holds your daytime template, etc.

Offline marcus_s

  • Newbie
  • *
  • Posts: 33
    • View Profile
Re: style switch by time
« Reply #5 on: April 15, 2005, 02:48:04 PM »
chris.

that sounds good to me.
so if i use your code - the  4images system will choose the template by time?

the only thing i need to do is to create a day and a night folder with the templates in it.

gonna try it.

thanks

m

Offline marcus_s

  • Newbie
  • *
  • Posts: 33
    • View Profile
Re: style switch by time
« Reply #6 on: April 15, 2005, 09:16:21 PM »
ok. works. thanks.  :)

but you're right i need a js solution to determine the client´s time. working on that.
this one´s gonna do it for now so thank you!

marcus