Jump to content

Calendar wrong date.. help!


Recommended Posts

Hi, I need help desperately. The dates in my calendar is all wrong.

It should be 25th September today but it is showing 28th Sept.

 

can someone help me and tell me where to make the changes please?

 

The URL is www.leeweebrothers.com/new

 

You need to purchase something, click on View Cart > then you will see the calendar.

 

This is the coding:

 

<?php
class DeliveryConfig extends Module
{
    public function __construct()
    {
        $this->name = 'deliveryconfig';
        $this->tab = 'shipping_logistics';
        $this->version = '1.0';
        $this->author = 'CartExpert.net';
        

        parent::__construct ();

        $this->displayName = $this->l('Delivery configurator');
        $this->description = $this->l('Add extra options and prices for delivery');
    }
    
    public function install()
    {
        
        if (!parent::install() OR !$this->registerHook('header') OR !$this->registerHook('shoppingCart'))
            return false;
    }
    
    public function getContent()
    {
        $this->_html .= '<h2>' . $this->l('Delivery Configurator').'</h2>';
        if (Tools::isSubmit('saveDeliveryConfig'))
        {
            if (Tools::getValue('id_deliveryconfig'))
            {
                $id_deliveryconfig = Tools::getValue('id_deliveryconfig');
                DB::getInstance()->Execute('UPDATE '._DB_PREFIX_.'deliveryconfig SET id_carrier = '.(int)Tools::getValue('id_carrier').', minimum_order = '.(Tools::getValue('minimum_order') ? (float)(Tools::getValue('minimum_order')) : 0).', delivery_time = '.(Tools::getValue('delivery_time') ? (int)(Tools::getValue('delivery_time')) : 0).', delivery_time_surcharge='.(Tools::getValue('delivery_time_surcharge') ? (float)(Tools::getValue('delivery_time_surcharge')) : 0).', active_config='.Tools::getValue('active_config').' WHERE id_deliveryconfig = '.$id_deliveryconfig);
                
                $languages = Language::getLanguages(false);
                foreach ($languages AS $language)
                {
                    DB::getInstance()->Execute('UPDATE '._DB_PREFIX_.'deliveryconfig_lang SET description = "'.Tools::getValue('description_'.$language['id_lang']).'" WHERE id_deliveryconfig = '.$id_deliveryconfig.' AND id_lang='.$language['id_lang']);
                }
                
                $del_options = Tools::getValue('delete_config_options');
                if (is_array($del_options))
                {
                    foreach($del_options as $do)
                        DB::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'deliveryconfig_options WHERE id_deliveryconfig_option = '.$do);
                }
                
                $options = DB::getInstance()->ExecuteS('SELECT id_deliveryconfig_option FROM '._DB_PREFIX_.'deliveryconfig_options WHERE id_deliveryconfig='.$id_deliveryconfig);
                for ($i=0; $i<count($options); $i++)
                {
                    DB::getInstance()->Execute('UPDATE '._DB_PREFIX_.'deliveryconfig_options SET timerange = "'.Tools::getValue('timerange_'.$options[$i]['id_deliveryconfig_option']).'", price='.(Tools::getValue('price_'.$options[$i]['id_deliveryconfig_option']) ? (float)(Tools::getValue('price_'.$options[$i]['id_deliveryconfig_option'])) : 0).' WHERE id_deliveryconfig_option = '.$options[$i]['id_deliveryconfig_option']);
                }
                
                $timerange = Tools::getValue('timerange');
                $price = Tools::getValue('price');
                
                for ($i=0; $i<count($timerange); $i++)
                {
                    if ($timerange[$i] != '' && $price[$i] != '')
                        DB::getInstance()->ExecuteS('INSERT INTO '._DB_PREFIX_.'deliveryconfig_options(id_deliveryconfig, timerange, price) VALUES('.$id_deliveryconfig.', "'.$timerange[$i].'", '.(float)($price[$i]).')');
                }
                
                $this->_html .= '<div class="conf">
                    <img alt="" src="../img/admin/ok2.png"> '.$this->l('Settings updated').'
                </div>';
            }
        }
        if (Tools::isSubmit('submitDeliveryConfig'))
        {
            //error handeling
            DB::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'deliveryconfig(id_carrier, minimum_order, delivery_time, delivery_time_surcharge, active_config) VALUE('.(int)(Tools::getValue('id_carrier')).', '.(float)(Tools::getValue('minimum_order')).', '.(int)(Tools::getValue('delivery_time')).', '.(float)(Tools::getValue('delivery_time_surcharge')).', '.(int)(Tools::getValue('active_config')).')');
            $id_config = DB::getInstance()->Insert_ID();
            $languages = Language::getLanguages(false);
            foreach ($languages AS $language)
            {
                DB::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'deliveryconfig_lang(id_deliveryconfig, id_lang, description) VALUES('.$id_config.', '.$language['id_lang'].', "'.Tools::getValue('description_'.$language['id_lang']).'")');
            }
            
            $timerange = Tools::getValue('timerange');
            $price = Tools::getValue('price');
            
            for ($i=0; $i<count($timerange); $i++)
            {
                DB::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'deliveryconfig_options(id_deliveryconfig, timerange, price) VALUES('.$id_config.', "'.$timerange[$i].'", '.(float)($price[$i]).')');
            }
            
            $this->_html .= '<div class="conf">
                <img alt="" src="../img/admin/ok2.png"> '.$this->l('Settings updated').'
            </div>';
        }
        if (Tools::getValue('delete_config') == 'true' && (int)(Tools::getValue('id_deliveryconfig')) != 0)
        {
            DB::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'deliveryconfig WHERE id_deliveryconfig='.Tools::getValue('id_deliveryconfig'));
            DB::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'deliveryconfig_lang WHERE id_deliveryconfig='.Tools::getValue('id_deliveryconfig'));
            DB::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'deliveryconfig_options WHERE id_deliveryconfig='.Tools::getValue('id_deliveryconfig'));
            $tmp = explode('&delete_config', $_SERVER['REQUEST_URI']);
            Tools::redirectAdmin($tmp[0]);
        }
        
        if (Tools::isSubmit('submitBlockedDate'))
        {
            if (Tools::getValue('date_to_block') != '' && strtolower(Tools::getValue('date_to_block')) != 'yyyy-mm-dd')
            {
                DB::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'deliveryconfig_date_block(date_to_block, full_block, message) VALUES(\''.Tools::getValue('date_to_block').'\', '.Tools::getValue('full_block', 0).', \''.pSQL(Tools::getValue('b_message')).'\')');
            }
            
            $result = DB::getInstance()->ExecuteS('SELECT * FROM '._DB_PREFIX_.'deliveryconfig_date_block ORDER BY date_to_block');
            
            foreach($result as $row)
            {
                if (Tools::getValue('date_to_block_'.$row['id_delivery_config_date_block']) != '' && strtolower(Tools::getValue('date_to_block_'.$row['id_delivery_config_date_block'])) != 'yyyy-mm-dd')
                {
                    DB::getInstance()->Execute('UPDATE '._DB_PREFIX_.'deliveryconfig_date_block SET date_to_block = \''.Tools::getValue('date_to_block_'.$row['id_delivery_config_date_block']).'\', full_block = '.Tools::getValue('full_block_'.$row['id_delivery_config_date_block'], 0).', message = \''.pSQL(Tools::getValue('b_message_'.$row['id_delivery_config_date_block'])).'\' WHERE id_delivery_config_date_block='.$row['id_delivery_config_date_block']);
                }
            }
        }
        
        if (Tools::isSubmit('deleteBlockedDate'))
        {
            $to_delete = Tools::getValue('delete_dates');
            if (is_array($to_delete))
            {
                foreach ($to_delete as $delete)
                    DB::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'deliveryconfig_date_block WHERE id_delivery_config_date_block = '.$delete);
            }
            
        }
        
        if (Tools::isSubmit('deletePassedBlockedDate'))
        {
            DB::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'deliveryconfig_date_block WHERE date_to_block < NOW()');
        }
        
        if (Tools::isSubmit('submitSurchargeDate'))
        {
            if (Tools::getValue('date_to_surcharge') != '' && strtolower(Tools::getValue('date_to_surcharge')) != 'yyyy-mm-dd')
            {
                DB::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'deliveryconfig_date_surcharge(date_to_surcharge, price, message) VALUES(\''.Tools::getValue('date_to_surcharge').'\', '.Tools::getValue('price').', \''.pSQL(Tools::getValue('s_message')).'\')');
            }
            
            $result = DB::getInstance()->ExecuteS('SELECT * FROM '._DB_PREFIX_.'deliveryconfig_date_surcharge ORDER BY date_to_surcharge');
            foreach($result as $row)
            {
                if (Tools::getValue('date_to_surcharge_'.$row['id_delivery_config_date_surcharge']) != '' && strtolower(Tools::getValue('date_to_surcharge_'.$row['id_delivery_config_date_surcharge'])) != 'yyyy-mm-dd')
                {
                    DB::getInstance()->Execute('UPDATE '._DB_PREFIX_.'deliveryconfig_date_surcharge SET date_to_surcharge = \''.Tools::getValue('date_to_surcharge_'.$row['id_delivery_config_date_surcharge']).'\', price = '.Tools::getValue('price_'.$row['id_delivery_config_date_surcharge']).', message = \''.pSQL(Tools::getValue('s_message_'.$row['id_delivery_config_date_surcharge'])).'\' WHERE id_delivery_config_date_surcharge='.$row['id_delivery_config_date_surcharge']);
                }
            }
        }
        
        if (Tools::isSubmit('deleteSurchargeDate'))
        {
            $to_delete = Tools::getValue('delete_dates');
            if (is_array($to_delete))
            {
                foreach ($to_delete as $delete)
                    DB::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'deliveryconfig_date_surcharge WHERE id_delivery_config_date_surcharge = '.$delete);
            }
            
        }
        
        if (Tools::isSubmit('deletePassedSurchargeDate'))
        {
            DB::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'deliveryconfig_date_surcharge WHERE date_to_surcharge < NOW()');
        }
        
        if (Tools::isSubmit('submitSelfCollect'))
        {
            Configuration::updateValue('DC_SC_CARRIER', Tools::getValue('DC_SC_CARRIER'));
        }
        
        $this->_displayForm();
        return $this->_html;
    }
    
    private function getDescription($id_deliveryconfig, $id_lang)
    {
        $r = DB::getInstance()->ExecuteS('SELECT description FROM '._DB_PREFIX_.'deliveryconfig_lang WHERE id_deliveryconfig = '.$id_deliveryconfig.' AND id_lang='.$id_lang);
        return $r[0]['description'];
    }
    
    private function _displayForm()
    {
        global $cookie;
        $allowEmployeeFormLang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
        if ($allowEmployeeFormLang && !$cookie->employee_form_lang)
            $cookie->employee_form_lang = (int)(Configuration::get('PS_LANG_DEFAULT'));
        $configs = DB::getInstance()->ExecuteS('SELECT *, dl.description FROM '._DB_PREFIX_.'deliveryconfig d LEFT JOIN '._DB_PREFIX_.'deliveryconfig_lang dl ON (d.id_deliveryconfig = dl.id_deliveryconfig) WHERE dl.id_lang='.(int)($cookie->id_lang));
        $languages = Language::getLanguages(false);
        if (count($configs) > 0)
        {
            $carriers = Carrier::getCarriers($this->context->language->id);
            $this->_html .= '<fieldset><legend>'.$this->l('Configurations').'</legend>';
            $this->_html .= '<table class="table" id="delivery_configs" width="100%"><tr><th style="width:15px;">'.$this->l('ID').'</th><th style="width:500px;">'.$this->l('Description').'</th><th>'.$this->l('Edit').'</th><th>'.$this->l('Delete').'</th></tr>';
            for ($i=0; $i<count($configs); $i++)
            {
                $this->_html .='<tr><td style="width:15px;">'.$configs[$i]['id_deliveryconfig'].'</td><td style="width:500px;">'.$configs[$i]['description'].'</td><td><a href="'.$configs[$i]['id_deliveryconfig'].'" class="edit"><img src="../img/admin/edit.gif" alt="'.$this->l('Edit').'"/></a></td><td><a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&delete_config=true&id_deliveryconfig='.$configs[$i]['id_deliveryconfig'].'"><img src="../img/admin/delete.gif"/></a></td></tr>';
                $this->_html .='<tr id="tr_'.$configs[$i]['id_deliveryconfig'].'" style="display:none;"><td colspan="4" valign="top">';
                $this->_html .= '<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post"><input type="hidden" name="id_deliveryconfig" value="'.$configs[$i]['id_deliveryconfig'].'"/><table style="float:left;" valign="top"><tr><td style="width:150px;"><b>'.$this->l('Name').'</b></td><td><div class="translatable">';
                
                foreach ($languages AS $language)
                {
                    $this->_html .= '<div class="lang_'.$language['id_lang'].'" style="float:left;display: '.($language['id_lang'] == (int)(Configuration::get('PS_LANG_DEFAULT')) ? 'block' : 'none').';">
                                <input type="text" style="width: 260px" name="description_'.$language['id_lang'].'" id="description_'.$language['id_lang'].'" value="'.$this->getDescription($configs[$i]['id_deliveryconfig'],$language['id_lang']).'"/>
                            </div>';
                }
                $this->_html .= '</div></td></tr>';
                
                $this->_html .= '<tr><td><b>'.$this->l('Associated carrier').'</b></td><td><select name="id_carrier" value="'.$configs[$i]['minimum_order'].'"/>';
                foreach($carriers as $carrier)
                    $this->_html .= '<option value="'.$carrier['id_carrier'].'" '.($configs[$i]['id_carrier'] == $carrier['id_carrier'] ? 'SELECTED' : '').'>'.$carrier['name'].'</option>';
                $this->_html .= '</select></td></tr>';
                
                $this->_html .= '<tr><td><b>'.$this->l('Active').'</b></td><td><input name="active_config" value="1" '.($configs[$i]['active_config'] == 1 ? 'checked="checked"' : '').' type="radio"><label class="t"><img src="../img/admin/enabled.gif" alt="Enabled" title="Enabled"></label><input name="active_config" value="0" type="radio" '.($configs[$i]['active_config'] == 0 ? 'checked="checked"' : '').'/><label class="t"><img src="../img/admin/disabled.gif" alt="Disabled" title="Disabled"></label></td></tr>';
                
                $this->_html .= '<tr><td><b>'.$this->l('Minimum order price').'</b></td><td><input type="text" name="minimum_order" value="'.$configs[$i]['minimum_order'].'"/></td></tr>';
                $this->_html .= '<tr><td><b>'.$this->l('Minimum number of days before delivery').'</b></td><td><input type="text" name="delivery_time" value="'.$configs[$i]['delivery_time'].'"/></td></tr>';
                $this->_html .= '<tr><td><b>'.$this->l('Amount to surcharge if delivery is sooner than minimum number of days').'</b></td><td><input type="text" name="delivery_time_surcharge" value="'.$configs[$i]['delivery_time_surcharge'].'"/></td></tr><tr><td><input type="submit" class="button" name="saveDeliveryConfig" value="'.$this->l('Save').'"/></td><td></td></tr></table><br/><br/>';
        
                
                
                $options = DB::getInstance()->ExecuteS('SELECT * FROM '._DB_PREFIX_.'deliveryconfig_options WHERE id_deliveryconfig='.(int)($configs[$i]['id_deliveryconfig']));
                $this->_html .='<table class="table" style="float:right;'.($configs[$i]['id_carrier'] == Configuration::get('DC_SC_CARRIER') ? 'display:none' : '').'" cellspacing="0" border="0" valign="top"><tr><th>'.$this->l('Time range').'</th><th>'.$this->l('Price to surcharge').'</th><th>'.$this->l('Delete').'</th></tr>';
                for ($j=0; $j<count($options); $j++)
                {
                    $this->_html .= '<tr><td><input type="text" name="timerange_'.$options[$j]['id_deliveryconfig_option'].'" value="'.$options[$j]['timerange'].'"/></td><td><input type="text" name="price_'.$options[$j]['id_deliveryconfig_option'].'" value="'.$options[$j]['price'].'"/></td><td><input type="checkbox" name="delete_config_options[]" value="'.$options[$j]['id_deliveryconfig_option'].'"/></td></tr>';
                }
                $this->_html .= '<tr><td><input type="text" name="timerange[]" value=""/></td><td><input type="text" name="price[]" value=""/></td><td> </td></tr>';
                $this->_html .='<tr id="tro_'.$configs[$i]['id_deliveryconfig'].'"><td colspan="2"><a href="'.$configs[$i]['id_deliveryconfig'].'" class="add_row"><img border="0" src="../img/admin/add.gif">'.$this->l('Add new row').'</a></td></tr></table></form></td></tr>';
            }
            $this->_html .='</table></fieldset><br/><br/><br/>';
        }
        else
        {
            //none
        }
        
        $this->_html .= '<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post"><fieldset><legend>'.$this->l('New configuration').'</legend>';
        $this->_html .= '<table><tr><td><b>'.$this->l('Name').'</b></td><td>';
        $this->_html .= '<div class="translatable">';
        
        foreach ($languages AS $language)
        {
            $this->_html .= '<div class="lang_'.$language['id_lang'].'" style="float:left; display: '.($language['id_lang'] == (int)(Configuration::get('PS_LANG_DEFAULT')) ? 'block' : 'none').'; ">
                        <input type="text" style="width: 260px" name="description_'.$language['id_lang'].'" id="description_'.$language['id_lang'].'" value=""/>
                    </div>';
        }
        $this->_html .= '</div></td></tr>';
        $this->_html .= '<tr><td><b>'.$this->l('Active').'</b></td><td>
                    <input name="active_config" id="active_on" value="1" checked="checked" type="radio">
                    <label class="t" for="active_on"><img src="../img/admin/enabled.gif" alt="Enabled" title="Enabled"></label>
                    <input name="active_config" id="active_off" value="0" type="radio">
                    <label class="t" for="active_off"><img src="../img/admin/disabled.gif" alt="Disabled" title="Disabled"></label>
                </td></tr>';
        $this->_html .= '<tr><td><b>'.$this->l('Associated carrier').'</b></td><td><select name="id_carrier" value="'.$configs[$i]['minimum_order'].'"/>';
        foreach($carriers as $carrier)
            $this->_html .= '<option value="'.$carrier['id_carrier'].'" '.($configs[$i]['id_carrier'] == $carrier['id_carrier'] ? 'SELECTED' : '').'>'.$carrier['name'].'</option>';
        $this->_html .= '</select></td></tr>';
        $this->_html .= '<tr><td><b>'.$this->l('Minimum order price').'</b></td><td><input type="text" name="minimum_order"/></td></tr>';
        $this->_html .= '<tr><td><b>'.$this->l('Minimum number of days before delivery').'</b></td><td><input type="text" name="delivery_time"/></td></tr>';
        $this->_html .= '<tr><td><b>'.$this->l('Amount to surcharge if delivery is sooner than minimum number of days').'</b></td><td><input type="text" name="delivery_time_surcharge"/></td></tr>';
        $this->_html .= '<tr><td> </td><td> </td></tr><tr><td colspan="2">';
        $this->_html .= '<tr><td><h3>'.$this->l('Add delivery time/price options').'</h3></td><td> </td></tr><tr><td colspan="2">';
        $this->_html .= '<table class="table"><tr><th>'.$this->l('Time range').'</th><th>'.$this->l('Price to surcharge').'</th></tr>';
        $this->_html .= '<tr><td><input type="text" name="timerange[]" value=""/></td><td><input type="text" name="price[]" value=""/></td></tr><tr id="tro_0"><td colspan="2"<a href="0" class="add_row"><img border="0" src="../img/admin/add.gif">'.$this->l('Add new row').'</a></td></tr>';
        $this->_html .= '</table></td></tr></table>';
        $this->_html .= '
            <script type="text/javascript">
                $(document).ready(function() {
                    id_language = '.(int)(Configuration::get('PS_LANG_DEFAULT')).';
                    languages = new Array();';
            foreach ($languages AS $k => $language)
                $this->_html .= '
                    languages['.$k.'] = {
                        id_lang: '.(int)$language['id_lang'].',
                        iso_code: \''.$language['iso_code'].'\',
                        name: \''.htmlentities($language['name'], ENT_COMPAT, 'UTF-8').'\'
                    };';
            $this->_html .= '
                    displayFlags(languages, id_language, '.$allowEmployeeFormLang.');
                });
            $(".add_row").click(function()
            {
                tr = $("<tr></tr>");
                td = $("<td></td>");
                i = $("<input/>");
                i.attr("type", "text");
                i.attr("name", "timerange[]");
                td.append(i);
                tr.append(td);
                
                td = $("<td></td>");
                i = $("<input/>");
                i.attr("type", "text");
                i.attr("name", "price[]");
                td.append(i);
                tr.append(td);
                //alert($(this).parent("tr").attr("id"));
                $("#tro_"+$(this).attr("href")).before(tr);
                
                return false;
            })
            
            $("#delivery_configs .edit").click(function()
            {
                if ($("#tr_"+$(this).attr("href")+":visible").length == 0)
                {
                    $("#tr_"+$(this).attr("href")).fadeIn();
                }
                else
                {
                    $("#tr_"+$(this).attr("href")).fadeOut();
                }
                return false;
            });
            </script>';
        $this->_html .= '<input type="submit" class="button" name="submitDeliveryConfig" value="'.$this->l('Save').'"/></fieldset>';
        $this->_html .= '<fieldset  style="margin-top:25px;"><legend>'.$this->l('Self collection').'</legend><b>'.$this->l('Select self-collection carrier').':</b><select name="DC_SC_CARRIER">';
        foreach($carriers as $carrier)
            $this->_html .= '<option value="'.$carrier['id_carrier'].'" '.($carrier['id_carrier'] == Configuration::get('DC_SC_CARRIER') ? 'SELECTED' : '').'>'.$carrier['name'].'</option>';
        $this->_html .= '</select><br/><input type="submit" class="button" name="submitSelfCollect" value="'.$this->l('Save').'"/></fieldset>';
        $this->_html .= '<table style="margin-top:25px; width:80%;vertical-align:top;" valign="top">
            <tr>
                <td style="vertical-align:top;">
                    <fieldset>
                        <legend>'.$this->l('Blocked dates').'</legend>
                        <table>
                            <tr>
                                <th> </th>
                                <th>'.$this->l('Date').'</th>
                                <th>'.$this->l('Disallow self-collection').'</th>
                                <th>'.$this->l('Message to display (optional)').'</th>
                            </tr>';
        $result = DB::getInstance()->ExecuteS('SELECT * FROM '._DB_PREFIX_.'deliveryconfig_date_block ORDER BY date_to_block');
        foreach ($result as $row)
            $this->_html .= '<tr><td><input type="checkbox" value="'.$row['id_delivery_config_date_block'].'" name="delete_dates[]"/></td><td><input type="text" name="date_to_block_'.$row['id_delivery_config_date_block'].'" value="'.$row['date_to_block'].'"/></td><td><input type="checkbox" value="1" name="full_block_'.$row['id_delivery_config_date_block'].'" '.($row['full_block'] == 1 ? 'CHECKED' : '').'/></td><td><input type="text" name="b_message_'.$row['id_delivery_config_date_block'].'" value="'.$row['message'].'"/></td></tr>';
        $this->_html .= '<tr id="new_blocked_date">
                                <td> </td>
                                <td><input type="text" name="date_to_block" value="YYYY-MM-DD"/></td>
                                <td><input type="checkbox" value="1" name="full_block"/></td>
                                <td><input type="text" value="" name="b_message"/></td>
                            </tr>
                        </table>
                        <input type="submit" class="button" name="submitBlockedDate" id="submitBlockedDate" value="'.$this->l('Save').'"/>   
                        <input type="submit" class="button" name="deleteBlockedDate" onclick="return confirm(\''.$this->l('Are you sure you want to delete the selected dates').'\')" value="'.$this->l('Delete selected').'"/>   
                        <input type="submit" class="button" name="deletePassedBlockedDate" value="'.$this->l('Delete passed dates').'"/>
                    </fieldset>
                </td>
                <td style="vertical-align:top;">
                    <fieldset>
                        <legend>'.$this->l('Dates to surcharge').'</legend>
                        <table>
                            <tr>
                                <th> </th>
                                <th>'.$this->l('Date').'</th>
                                <th>'.$this->l('Price to surcharge').'</th>
                                <th>'.$this->l('Message to display (optional)').'</th>
                            </tr>';
        $result = DB::getInstance()->ExecuteS('SELECT * FROM '._DB_PREFIX_.'deliveryconfig_date_surcharge ORDER BY date_to_surcharge');
        foreach ($result as $row)
            $this->_html .= '<tr><td><input type="checkbox" value="'.$row['id_delivery_config_date_surcharge'].'" name="delete_dates[]"/></td><td><input type="text" name="date_to_surcharge_'.$row['id_delivery_config_date_surcharge'].'" value="'.$row['date_to_surcharge'].'"/></td><td><input type="text" value="'.$row['price'].'" name="price_'.$row['id_delivery_config_date_surcharge'].'"/></td><td><input type="text" value="'.$row['message'].'" name="s_message_'.$row['id_delivery_config_date_surcharge'].'"/></td></tr>';
        $this->_html .=     '<tr id="new_blocked_date">
                                <td> </td>
                                <td><input type="text" name="date_to_surcharge" value="YYYY-MM-DD"/></td>
                                <td><input type="text" name="price" value="0"/></td>
                                <td><input type="text" value="" name="s_message"/></td>
                            </tr>
                        </table>
                        <input type="submit" class="button" name="submitSurchargeDate" id="submitSurchargeDate" value="'.$this->l('Save').'"/>   
                        <input type="submit" class="button" name="deleteSurchargeDate" onclick="return confirm(\''.$this->l('Are you sure you want to delete the selected dates').'\')" value="'.$this->l('Delete selected').'"/>   
                        <input type="submit" class="button" name="deletePassedSurchargeDate" value="'.$this->l('Delete passed dates').'"/>
                    </fieldset>
                </td>
            </tr>
        </table>
        </form>';
    }
    
    public function hookHeader($params)
    {
        $this->context->controller->addJS(($this->_path).'deliveryconfig.js');
        $this->context->controller->addCSS(($this->_path).'deliveryconfig.css');
    }
    
    public function hookShoppingCart($params)
    {
        global $cookie, $smarty;
        
        $taxCalculationMethod = Group::getPriceDisplayMethod((int)Group::getCurrent()->id);

        $useTax = !($taxCalculationMethod == PS_TAX_EXC);
        
        $configs = DB::getInstance()->ExecuteS('SELECT d.*, dl.description FROM '._DB_PREFIX_.'deliveryconfig d LEFT JOIN '._DB_PREFIX_.'deliveryconfig_lang dl ON (d.id_deliveryconfig = dl.id_deliveryconfig) WHERE d.active_config = 1 AND dl.id_lang='.(int)($cookie->id_lang).' AND d.minimum_order <= '. $params['cart']->getOrderTotal($useTax));
        
        if (count($configs) == 0)
            return;
            
        $return = '';
        for ($i = 0; $i<count($configs); $i++)
        {
            $configs[$i]['configs'] = DB::getInstance()->ExecuteS('SELECT * FROM '._DB_PREFIX_.'deliveryconfig_options WHERE id_deliveryconfig = '.$configs[$i]['id_deliveryconfig']);
            //$return .= '<input type="radio" name="delivery_config" value="'.$configs[$i]['id_deliveryconfig'].'"/>'.$configs[$i]['description'].'<br/>';
        }
        
        $blocked_dates = array();
        $result = DB::getInstance()->ExecuteS('SELECT * FROM '._DB_PREFIX_.'deliveryconfig_date_block');
        foreach ($result as $row)
        {
            $blocked_dates[$row['date_to_block']]['full_block'] = $row['full_block'];
            $blocked_dates[$row['date_to_block']]['message'] = $row['message'];
        }
        
        $smarty->assign(array('blocked_dates_array' => $blocked_dates));
        
        $surcharged_dates = array();
        $result = DB::getInstance()->ExecuteS('SELECT * FROM '._DB_PREFIX_.'deliveryconfig_date_surcharge');
        foreach ($result as $row)
        {
            $surcharged_dates[$row['date_to_surcharge']]['price'] = $row['price'];
            $surcharged_dates[$row['date_to_surcharge']]['message'] = $row['message'];
        }
        
        $smarty->assign(array('surcharged_dates_array' => $surcharged_dates));
        
        $months = array(1 => $this->l('January'), 2=> $this->l('February'), 3=> $this->l('March'), 4=> $this->l('April'),5 => $this->l('May'), 6=> $this->l('June'), 7=> $this->l('July'), 8=> $this->l('August'), 9=> $this->l('September'), 10=> $this->l('October'), 11=> $this->l('November'), 12=> $this->l('December'));
        
        //$smarty->assign(array('id_deliveryconfig' => $params['cart']->id_deliveryconfig, 'id_deliveryconfig_option' => $params['cart']->id_deliveryconfig_option, 'delivery_date' => explode('-',$params['cart']->delivery_date)));
        $id_deliveryconfig_self_collection = false;
        $id_carrier = DB::getInstance()->getValue('SELECT id_carrier FROM '._DB_PREFIX_.'deliveryconfig WHERE id_deliveryconfig = '.$params['cart']->id_deliveryconfig);
        if ($id_carrier == Configuration::get('DC_SC_CARRIER'))
            $id_deliveryconfig_self_collection = true;
        
        $smarty->assign(array('id_deliveryconfig' => $params['cart']->id_deliveryconfig, 'id_deliveryconfig_self_collection' => $id_deliveryconfig_self_collection, 'id_deliveryconfig_option' => $params['cart']->id_deliveryconfig_option, 'delivery_date' => $params['cart']->delivery_date));
        
        $smarty->assign(array('configs' => $configs, 'self_collect_carrier' => Configuration::get('DC_SC_CARRIER'), 'months' => $months, 'years' => array((int)(date('Y')),(int)(date('Y')) + 1, (int)(date('Y'))+2)));
        
        $smarty->assign('DC_SC_CARRIER', DB::getInstance()->getValue('SELECT id_deliveryconfig FROM '._DB_PREFIX_.'deliveryconfig WHERE id_carrier = '.Configuration::get('DC_SC_CARRIER')));
        $smarty->assign('blocked_dates', DB::getInstance()->ExecuteS('SELECT date_to_block FROM '._DB_PREFIX_.'deliveryconfig_date_block WHERE full_block = 0 AND date_to_block >= NOW()'));
        $smarty->assign('blocked_dates_full', DB::getInstance()->ExecuteS('SELECT date_to_block FROM '._DB_PREFIX_.'deliveryconfig_date_block WHERE full_block = 1 AND date_to_block >= NOW()'));
        
        $smarty->assign('surcharge_dates', DB::getInstance()->ExecuteS('SELECT * FROM '._DB_PREFIX_.'deliveryconfig_date_surcharge WHERE date_to_surcharge >= NOW()'));
        
        if (mktime(1,1, 1, (int)date('n'), 31, (int)date('Y')))
            $smarty->assign('day_nr', 31);
        elseif (mktime(1,1, 1, (int)date('n'), 31, (int)date('Y')))
            $smarty->assign('day_nr', 30);
        else
            $smarty->assign('day_nr', 28);
        
        $smarty->assign(array('current_day' => (int)date('j'), 'current_month' => (int)date('n'), 'current_year' => (int)date('Y'), 'empty_dates' => (int)date('w', mktime(1, 1, 1, date('n'), 1, date('Y'))) - 1));
        
        if ((int)date('n') == 12)
        {
            $smarty->assign(array('next_month' => 1, 'next_year' => (int)date('Y') + 1, 'next_empty_dates' => (int)date('w', mktime(1, 1, 1, 1, 1, date('Y') + 1)) - 1, 'next_day_nr' => 31));
            
        }
        else
        {
            $smarty->assign(array('next_month' => (int)date('n') + 1, 'next_year' => (int)date('Y'), 'next_empty_dates' => (int)date('w', mktime(1, 1, 1, date('n') + 1, 1, date('Y'))) - 1));
            if (mktime(1,1, 1, (int)date('n') + 1, 31, (int)date('Y')))
                $smarty->assign('next_day_nr', 31);
            elseif (mktime(1,1, 1, (int)date('n') + 1, 31, (int)date('Y')))
                $smarty->assign('next_day_nr', 30);
            else
                $smarty->assign('next_day_nr', 28);
        }
        
        $months_display = 3;
        $month_config = array();
        
        
        //$current_date = date()
        
        $timestamp = time();
        
        for ($i = 0; $i<$months_display; $i++)
        {
            $month_config[$i] = array();
            $month_config[$i]['day_nr'] = date('t', $timestamp);
            $month_config[$i]['empty_dates'] = date('w', $timestamp);
            $month_config[$i]['year'] = date('Y', $timestamp);
            $month_config[$i]['month'] = date('n', $timestamp);
            
            if ($i == 0)
                $month_config[$i]['day'] = date('j', $timestamp);
            else
                $month_config[$i]['day'] = 0;
            
            $timestamp = mktime(1, 1, 1, date('n', $timestamp) + 1, date('j', $timestamp), date('Y', $timestamp));
        }
        $smarty->assign(array('month_config' => $month_config));
        
        $display = $this->display(__FILE__, 'deliveryconfig.tpl');
        return $display;
    }
}
?>

Edited by linster (see edit history)
Link to comment
Share on other sites

×
×
  • Create New...