+ Reply to Thread
Results 1 to 6 of 6

Thread: Need help with PHP/Joomla

  1. #1
    ana
    ana is offline
    Barn Newbie ana is an unknown quantity at this point ana's Avatar
    Join Date
    Jan 2009
    Posts
    3
    Rep Power
    4

    Need help with PHP/Joomla

    Hy everyone, hope I will find someone here who can solve my problem. I understand code but never been alot of a coder , still beginner. Here is the problem: we're trying to make online reservation system for appartments using card payment. Booking available days on calendar and setting prices works fine, but the problem is that you can still book those days already booked or unavailable. It's somewhere if statement, it's called BOOKIN_PER_UNAVAL. If someone has some solution please help. Thanx

    Part of the code:

    PHP Code:
    function getDayBefore( $day ) {
        $d = explode( '-', $day );
        $yesterday = date( 'Y-m-d', mktime( 0, 0, 0, $d[1], $d[2] - 1, $d[0] ));
        return $yesterday;
    }

    function checkAvail($dateFrom,$dateTo){
        $array = JRequest::getVar('cid',  0, '', 'array');
        $id_property=((int)$array[0]);
        $db = & JFactory::getDBO();
        if($month<10){$month='0'.$month;}
        $query = 'SELECT * from #__properties_available_product '
            . ' WHERE id_product = ' . $id_property
            . ' AND date >= \'' . $dateFrom . '\' AND date <= \'' . $dateTo . '\'';
        $db->setQuery( $query );
        $list = $db->loadObjectList();
        return $list;
    }

    function pastDate( $day ) {
        $ft = explode( '-', date( 'Y-m-d' ) );
        $now = mktime( 0, 0, 0, $ft[1], $ft[2], $ft[0] );

        $ft = explode( '-', $day );
        $day = mktime( 0, 0, 0, $ft[1], $ft[2], $ft[0] );

        if( $day < $now ) return true;
        return false;
    }

    ?>

    <?php
    if(JRequest::getVar('fechaD')){$sd=JRequest::getVar('fechaD');}
    if(
    JRequest::getVar('fechaA')){$ed=JRequest::getVar('fechaA');}
    if( 
    $sd $ed ) {
        
    $t $sd;
        
    $sd $ed;
        
    $ed $t;
    }

    $Error null;

    if(
    $ed == '' || $sd == '') {
        
    $Error JText::_'EMPTY_DATE' );
        
    $ErrorExpl JText::_'EMPTY_DATE_EXPL' );
    }
    else {
        if( 
    $sd == $ed ) {
            
    $ft explode'-'$ed );
            
    $ed date'Y-m-d'mktime000$ft[1], $ft[2]+1$ft[0] ) );
        }
        if( 
    pastDate$sd ) or pastDate$ed ) ) {
            
    $Error JText::_'PAST_DATE' );
            
    $ErrorExpl JText::_'PAST_DATE_EXPL' );
        }
        else {
            
    $d checkAvail$sdgetDayBefore$ed ) );
            
    $od "";
            foreach( 
    $d as $l ) {
                if( 
    $l->price == or $l->available == $od .= $l->date '<br />' "\n";
            }
            if( 
    $od ) {
                
    $Error JText::_'BOOKING_PER_UNAVAL' );
                
    $ErrorExpl JText::_'BOOKING_PER_UNAVAL_EXPL' ) . '<br />' $od;
            }
        }
    }

    if( 
    $Error ) echo "<h1>" JText::_'BOOKING_ERROR' ) . ": " $Error "</h1><p>" $ErrorExpl "</p>";
    else {
        
    $sdD explode'-'$sd );
        
    $edD explode'-'$ed );
        
    $timestamp1 mktime000$sdD[1], $sdD[2], $sdD[0] );
        
    $timestamp2 mktime000$edD[1], $edD[2], $edD[0] );
        
    $diferencia $timestamp2 $timestamp1;
        
    $dias $diferencia 86400;

  2. #2
    Barn Newbie Anthony Parsons is on a distinguished road Anthony Parsons's Avatar
    Join Date
    Jun 2010
    Posts
    21
    Rep Power
    2

    Still an amateur like yourself, but I didn't think you could compound "if" statements like that, and they had to be if, elseif, else so it doesn't end up cancelling and going no further due to a null value. You have "if, if, else".

  3. #3
    Moderator don94403 is a jewel in the rough don94403 is a jewel in the rough don94403 is a jewel in the rough don94403's Avatar
    Join Date
    Mar 2008
    Location
    San Mateo, CA, USA
    Posts
    313
    Blog Entries
    8
    Real Name
    Don Ravey
    Rep Power
    6

    To answer your question, we need to know what establishes whether a date is available for a given property. What does your table look like? What is the code that maintains that? The only code that you have shown us that is concerned with availability is the function checkAvail(). The query you show appears to compare the current date with 2 dates in a table. I don't see how that establishes whether the property is available, other than for the current date, in any case. Your logic isn't clear to me.
    question = 2B || !2B

  4. #4
    ana
    ana is offline
    Barn Newbie ana is an unknown quantity at this point ana's Avatar
    Join Date
    Jan 2009
    Posts
    3
    Rep Power
    4



    here is what the table looks like. available properties have field "available" 1. so the problem seems to be somewhere inside this part of code. it's only part of code where it's being checked if the property is available or not and what's the price. hope to get some help

    PHP Code:
    else {
            
    $d checkAvail$sdgetDayBefore$ed ) );
            
    $od "";
            foreach( 
    $d as $l ) {
                if( 
    $l->price == or $l->available == $od .= $l->date '<br />' "\n";
            }
            if( 
    $od ) {
                
    $Error JText::_'BOOKING_PER_UNAVAL' );
                
    $ErrorExpl JText::_'BOOKING_PER_UNAVAL_EXPL' ) . '<br />' $od
    Last edited by ana; July 15th, 2010 at 01:10 PM.

  5. #5
    Moderator don94403 is a jewel in the rough don94403 is a jewel in the rough don94403 is a jewel in the rough don94403's Avatar
    Join Date
    Mar 2008
    Location
    San Mateo, CA, USA
    Posts
    313
    Blog Entries
    8
    Real Name
    Don Ravey
    Rep Power
    6

    Oh, that's an entirely different problem than I had pictured. So your table already has the availability determined by the value in the field "available"? First of all, are you sure that any properties have "available" set to 1 for the dates you are testing?

    In any case, your problem is with the query in the checkAvail() function, which doesn't seem to be doing at all what you want it to:
    Code:
    $query = 'SELECT * from #__properties_available_product '
        . ' WHERE id_product = ' . $id_property
        . ' AND date >= \'' . $dateFrom . '\' AND date <= \'' . $dateTo . '\'';
    
    The Where clause is checking for just 3 things:
    - the id_product field must = the id_property variable;
    - the date field (* see below!) must be = or later than the dateFrom variable;
    - the date field must be = or earlier than the dateTo variable.

    * Very important: never use a reserved word like "date" as the name of a field, because that word means something special to PHP and may get misinterpreted.

    So your query is not checking to see whether a property is available or not. To check for that, you must add another AND expression to the Where clause, like this:
    Code:
    $query = "SELECT * from #__properties_available_product "
        . " WHERE id_product = " . $id_property
            . " AND avail_date >= '$dateFrom' 
            . " AND avail_date <= ''$dateTo'
            . " AND available = 1";
    
    As you see, I changed the field name to avail_date, which you would have to do in the table and all scripts that use that table, but I recommend doing it anyway, to avoid problems.

    Also, you must make sure that the function checkAvail() is not called elsewhere in your scripts, if you make changes to it.
    question = 2B || !2B

  6. #6
    Barn Newbie Tetch is an unknown quantity at this point Tetch's Avatar
    Join Date
    Sep 2010
    Posts
    6
    Rep Power
    2

    Very good work, thanks guys.

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO