4images Forum & Community

4images Modifications / Modifikationen => Mods & Plugins (Requests & Discussions) => Topic started by: Sun Zaza on November 08, 2007, 11:57:59 PM

Title: Playing with date in detail.html/php
Post by: Sun Zaza on November 08, 2007, 11:57:59 PM
Hi guys,

I have the hole day problems with my gallery and now I have to solve something difficult for me:

I add two image additional fields:
{date_start} and {date_end}
Both are working fine on details.html

First question:
I want to add a new array {date2}
{date2}= {date_end} - {date_start}
I want the answer in days

Second question:
I want to add a new array {date3}
{date3}= today - {date_start}
I want the answer also in days

It is now midnight and I can not sleep because this issue. :cry:

Many thanks in advance for any help and/or explain,
Cruxy
Title: Re: Playing with date in detail.html/php
Post by: thunderstrike on November 09, 2007, 12:25:07 AM
You need edit includes/functions.php file for this in show_image function ...
Please post all additional image fields name with request (date start, date end) and I code. ;)
Title: Re: Playing with date in detail.html/php
Post by: Sun Zaza on November 09, 2007, 12:30:32 AM
Thank you Thunderstrike,

Here we go:

The image additional fields are already exist:
{date_start} and {date_end}

So I want a new array
{date2}= {date_end} - {date_start} (days, for example: 30 days)

I want also:
{date3}= today - {date_start} (days, for example: 30 days)

Thank yoy in advance,
Cruxy

Title: Re: Playing with date in detail.html/php
Post by: thunderstrike on November 09, 2007, 12:33:44 AM
Ok now ... what field type is date start and end ? (int, date) ? Please post more detail with this ...
Title: Re: Playing with date in detail.html/php
Post by: Sun Zaza on November 09, 2007, 12:42:06 AM
Oke,
{date_end} and {date_start}  are both are type date (I can change it if you want to).


Do you need more info? :)
Title: Re: Playing with date in detail.html/php
Post by: thunderstrike on November 09, 2007, 01:03:34 AM
// Step 1

In details.php file,

find:

Quote
//-----------------------------------------------------
//--- Print Out ---------------------------------------
//-----------------------------------------------------

add before:

Code: [Select]
if (isset($image_row['date_start']) && !empty($image_row['date_start']) && isset($image_row['date_end']) && !empty($image_row['date_end'])) {
    $image_start_date = $image_row['date_start'];
    $image_end_date = $image_row['date_end'];
    if (preg_match("/(\d{2})-(\d{2})-(\d{4})/", $image_start_date, $start)) {
        if (preg_match("/(\d{2})-(\d{2}-(\d{4}))/", $image_end_date, $end)) {
            if ($start[1] > date("d")) {
                $image_real_date_today = $start[1] - date("d");
            } elseif ($start[1] < date("d")) {
                $image_real_date_today = date("d") - $start[1];
            } elseif ($start[1] == date("d")) {
                $image_real_date_today = $start[1];
       
            } elseif ($end[1] > date("d")) {
                $image_real_date_today = $end[1] - date("d");
            } elseif ($end[1] < date("d")) {
                $image_real_date_today = date("d") - $end[1];
            } elseif ($end[1] == date("d")) {
                $image_real_date_today = date("d") - $end[1];           
            }
            $image_real_date_end_start = $end[1] - $start[1];
        }
    }
}

// Step 1.1

Find:

Quote
"lang_file_size" => $lang['file_size'],

add after:

Code: [Select]
"date2" => (isset($image_real_date_end_start)) ? $image_real_date_end_start : "",
"date3" => (isset($image_real_date_today)) ? $image_real_date_today : "",

In details.html file, use: {date2} and {date3} .
Title: Re: Playing with date in detail.html/php
Post by: thunderstrike on November 09, 2007, 01:12:04 AM
Sorry, I fix post. You no work with int but date. ;)
Title: Re: Playing with date in detail.html/php
Post by: Sun Zaza on November 09, 2007, 01:29:06 AM
Hi Thunderstrike,

It did not works yet!!!

There is something wrong with the date.
In edit image I put 01-10-2007 but in details.htm I get 0000-00-00
and when I put 2007-10-01 I get 2007-10-01.
I want to use actually 01-10-2007.
How can I change the format of date? :roll:
Title: Re: Playing with date in detail.html/php
Post by: thunderstrike on November 09, 2007, 01:31:00 AM
Quote
How can I change the format of date?

Re-create date start and date end with int type. No with date field.  :mrgreen:
I fix post in some min ...

[edit] - I fix for show with int microtime field. If set date in microtime - is quick way. ;)
Title: Re: Playing with date in detail.html/php
Post by: Sun Zaza on November 09, 2007, 01:49:54 AM
Hi Thunderstrike, I don't understand you. Have you already updated the code or do I have to wait :roll:
Title: Re: Playing with date in detail.html/php
Post by: thunderstrike on November 09, 2007, 02:15:47 AM
The code is update but you need add date (start and end) with microtime. Same way image_date is inject. ;)
Title: Re: Playing with date in detail.html/php
Post by: thunderstrike on November 09, 2007, 02:52:07 AM
Ok, I find other. What is date format in ACP - > Setting you have ? (Ex: d-m-Y) ...
If say format, I can code. ;)
Title: Re: Playing with date in detail.html/php
Post by: thunderstrike on November 09, 2007, 03:24:01 AM
Ok, I edit code for step 1. Date format is: Y-m-d . If is no right - is ok - I edit. ;)
Title: Re: Playing with date in detail.html/php
Post by: Sun Zaza on November 09, 2007, 10:49:43 AM
Hi Thunderstrike,
Here we go again  :D

I can not test the code because we have to solve first the problem of showing the dates on the details.
I will explain:

The additional field {date_start} = 01-10-2007 (At the edit image "ACP")
On the details.html is showing only 1
On the database I used: int(11) NO 0 (The same as {image_hits}).

I do not understand why? :roll:
See screenshots
Title: Re: Playing with date in detail.html/php
Post by: thunderstrike on November 09, 2007, 12:26:03 PM
Quote
The additional field {date_start} = 01-10-2007 (At the edit image "ACP")

Ok, so I fix date format in code now. ;)

Quote
On the database I used: int(11) NO 0 (The same as {image_hits}).

Oh ... this is right ... create the date_start and date_end field with date again. I miss for say this after last fix. :oops:
Title: Re: Playing with date in detail.html/php
Post by: Sun Zaza on November 09, 2007, 12:48:01 PM
No problem :)

I still can not test the code because when I changed int to date I get the date of {date_start}  like: 0000-00-00 instead of 01-10-2007
I am testing on a very fresh gallery
Title: Re: Playing with date in detail.html/php
Post by: thunderstrike on November 09, 2007, 12:51:17 PM
Quote
I still can not test the code because when I changed int to date  I get the date of {date_start}  like: 0000-00-00 instead of 01-10-2007

Please decide the date format range. Is year before or year after ?
Title: Re: Playing with date in detail.html/php
Post by: Sun Zaza on November 09, 2007, 12:54:24 PM
I want to use    :arrow: 01-10-2007
What strange is that {image_date} workt perfect even you edit the date, but the date of the additional field NOT
Title: Re: Playing with date in detail.html/php
Post by: thunderstrike on November 09, 2007, 12:58:58 PM
I want to use    :arrow: 01-10-2007

Ok so date format is correct. ;)

What strange is that {image_date} workt perfect even you edit the date, but the date of the additional field NOT :roll:

image_date is create with int.

For additional field, is create with int or with date ? Is no matter for me but you need say ...
Title: Re: Playing with date in detail.html/php
Post by: Sun Zaza on November 09, 2007, 01:14:59 PM
The additional field {hits_start} is created with DATE "Type: Date, Null: No" (as you asked me to do).

Quote
Ok so date format is correct.
On details is date 0000-00-00 is not correct. First the format is not good and second I see only zero's instead of 01-10-2007

Something wrong with the DATE additional fields? or in the database? :?:
Title: Re: Playing with date in detail.html/php
Post by: thunderstrike on November 09, 2007, 01:21:14 PM
Quote
On details is date 0000-00-00 is not correct. First the format is not good and second I see only zero's instead of 01-10-2007 :roll:

Please STOP use roll eyes :!:

Now, is say you see format with year before. You no use my fix. Use it. I say in last post - I fix my code for year at end. Year in code is now: d-m-Y

Quote
Something wrong with the DATE additional fields? or in the database?

Nothing is wrong with database ... you add date in field ? If see 00-00-0000 (or 0000-00-00 if no use my fix), is mean you no add nothing in field. Field is empty. :?
Title: Re: Playing with date in detail.html/php
Post by: Sun Zaza on November 09, 2007, 01:32:46 PM
Quote
Please STOP use roll eyes
Oh sorry I did not mean that!

Quote
Nothing is wrong with database ... you add date in field ? If see 00-00-0000 (or 0000-00-00 if no use my fix), is mean you no add nothing in field. Field is empty.

I am trying to figuur out the problem of the database. I go back to you when I find something :?
Title: Re: Playing with date in detail.html/php
Post by: thunderstrike on November 09, 2007, 01:44:01 PM
Database is fine. You need for set date (is good if create with DATE field type in phpmyadmin) and set correct date in ACP - > Images - > Edit images page for image you click.

1 - Submit form and server is process date.
2 - Check for see if still 00-00-0000 for return value.
Title: Re: Playing with date in detail.html/php
Post by: Sun Zaza on November 09, 2007, 01:55:32 PM
I think I have the unswer but NOT the solution.

In phpmyadmin I created a date. Everything is fine till now because the right date is showing in the details.
BUT when I tried to open this image in ACP, the date changed to 0000-00-00.
Now we know for sure that nothing wrong with the database. There is a miscommunication between {hits_start} (Additional field) and the database.

I beleave that the database doesn't understand that {hits_start} is a date!
Maybe we have to change or to add something in function.php?
Title: Re: Playing with date in detail.html/php
Post by: Sun Zaza on November 09, 2007, 02:10:37 PM
Good news :)
The problem is solved, but I still get the format: 2007-10-01. (phpmyadmin does not accept the format 01-10-2007)
How can I change it?
NOTE: When I we change the format I will start test in you code!
Title: Re: Playing with date in detail.html/php
Post by: Sun Zaza on November 09, 2007, 02:32:02 PM
I did some research via GOOGLE and finaly I have the unswer.

phpmyadmin have problems with dates, so it accecpt only this format: 0000-00-00 (INPUT).
But if you want to show the format 00-00-0000 (OUTPUT) you need to use:

1 - The explode function on each date in your file and then just insert into the mysql table in the format yyyy-mm-dd.

OR
<?php
$myinput='12/15/2005';
$sqldate=date('Y-m-d',strtotime($myinput));
echo $sqldate;
?>

PS: I tried to figure out how the 4images shows the format 00-00-0000, but no luck yet!!!

Can you help me in that?

Many thanks in advance,
Cruxy
Title: Re: Playing with date in detail.html/php
Post by: thunderstrike on November 09, 2007, 02:33:51 PM
This is in 4images with format_date function so use:

Code: [Select]
$image_start_date = format_date($config['date_format'], $image_row['date_start']);
$image_end_date = format_date($config['date_format'], $image_row['date_end']);
Title: Re: Playing with date in detail.html/php
Post by: Sun Zaza on November 09, 2007, 02:56:56 PM
I am still fighting to make it work.

Quote
$image_start_date = format_date($config['date_format'], $image_row['date_start']);
$image_end_date = format_date($config['date_format'], $image_row['date_end']);

I did not test the first code yet, because I want to change first the format of {date_start} on the details.
Listen, On functions.php I added this line:

"date_start" => format_date($config['date_format']." ".$config['time_format'],$image_row['date_start']), under
 
"image_date" => format_date($config['date_format']." ".$config['time_format'],$image_row['image_date']),

NO format changing yet!!!
Title: Re: Playing with date in detail.html/php
Post by: thunderstrike on November 09, 2007, 03:00:17 PM
If want to use date_start and date_end with strtotime, you need set field by int and no by date for keep right date format with 4images.
Title: Re: Playing with date in detail.html/php
Post by: Sun Zaza on November 09, 2007, 04:45:50 PM
Believe it or not. I was busy with this matter since this morning. I tried all tricks, but no luck yet!
I could not change the format of the {date_start}, but it is not very important at the moment.

Here we go again:
{date_start} and {date_end} are TYPE: Date.
The dates are showing in the details.html, but {date2} and {date3} NOT!!!
Do you have to change/add something in the code?
Code: [Select]
if (isset($image_row['date_start']) && !empty($image_row['date_start']) && isset($image_row['date_end']) && !empty($image_row['date_end'])) {
    $image_start_date = $image_row['date_start'];
    $image_end_date = $image_row['date_end'];
    if (preg_match("/(\d{2})-(\d{2})-(\d{4})/", $image_start_date, $start)) {
        if (preg_match("/(\d{2})-(\d{2}-(\d{4}))/", $image_end_date, $end)) {
            if ($start[1] > date("d")) {
                $image_real_date_today = $start[1] - date("d");
            } elseif ($start[1] < date("d")) {
                $image_real_date_today = date("d") - $start[1];
            } elseif ($start[1] == date("d")) {
                $image_real_date_today = $start[1];
       
            } elseif ($end[1] > date("d")) {
                $image_real_date_today = $end[1] - date("d");
            } elseif ($end[1] < date("d")) {
                $image_real_date_today = date("d") - $end[1];
            } elseif ($end[1] == date("d")) {
                $image_real_date_today = date("d") - $end[1];           
            }
            $image_real_date_end_start = $end[1] - $start[1];
        }
    }
}

Code: [Select]
"date2" => (isset($image_real_date_end_start)) ? $image_real_date_end_start : "",
"date3" => (isset($image_real_date_today)) ? $image_real_date_today : "",

See screenshot please!

Title: Re: Playing with date in detail.html/php
Post by: thunderstrike on November 09, 2007, 09:50:49 PM
Quote
I could not change the format of the {date_start}, but it is not very important at the moment.

Is important. If no change, is no work with strtotime.