Plugin Directory

Changeset 1689142


Ignore:
Timestamp:
07/02/2017 06:46:35 PM (9 years ago)
Author:
robby.roboter
Message:

custom fields API

Location:
redi-restaurant-reservation/branches/newDesign
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • redi-restaurant-reservation/branches/newDesign/redi-restaurant-booking.php

    r1665936 r1689142  
    5858        }
    5959    }
     60    if ( ! class_exists( 'CustomFieldsSaveTo' ) ) {
     61        class CustomFieldsSaveTo {
     62            const WPOptions = 'options';
     63            const API = 'api';
     64        }
     65    }
    6066
    6167    class ReDiBooking
     
    351357                    $form_valid = false;
    352358                }
    353 
    354                 for ($i = 1; $i != CUSTOM_FIELDS; $i++) {
     359                $this->options[ 'customfields_save_to' ] = CustomFieldsSaveTo::API;
     360
     361                for ( $i = 0; $i != CUSTOM_FIELDS; $i++ ) {
     362                    $field_id       = 'field_' . $i . '_id';
    355363                    $field_name = 'field_' . $i . '_name';
    356364                    $field_type = 'field_' . $i . '_type';
     
    358366                    $field_message = 'field_' . $i . '_message';
    359367
    360                     if (isset($_POST[$field_name])) {
    361                         $this->options[$field_name] = $$field_name = self::GetPost($field_name);
    362                     }
    363                     if (isset($_POST[$field_type])) {
    364                         $this->options[$field_type] = $$field_type = self::GetPost($field_type);
    365                     }
    366                     $this->options[$field_required] = $$field_required = (self::GetPost($field_required) === 'on');
    367                     if (isset($_POST[$field_message])) {
    368                         $this->options[$field_message] = $$field_message = self::GetPost($field_message);
     368                    $$field_id = self::GetPost( $field_id );
     369
     370                    $$field_name = self::GetPost( $field_name );
     371
     372                    $$field_type = self::GetPost( $field_type );
     373                    $$field_required = ( self::GetPost( $field_required ) === 'on' );
     374
     375                    $$field_message = self::GetPost( $field_message );
     376
     377                    if ( empty( $$field_name ) && isset( $$field_id ) && $$field_id > 0 ) { //name is empty so delete this field
     378                        $this->redi->deleteCustomField( self::lang(), $placeID, $$field_id );
     379                    } else {
     380                        //new or update
     381                        if ( isset( $$field_id ) && $$field_id > 0 ) {
     382                            $this->redi->updateCustomField( self::lang(), $placeID, $$field_id, array(
     383                                'customfield' => array(
     384                                    'Name'     => $$field_name,
     385                                    'Message'  => $$field_message,
     386                                    'Required' => $$field_required ? 'true' : 'false',
     387                                    'Type'     => $$field_type
     388                                )
     389                            ) );
     390                        } else {
     391                            $this->redi->saveCustomField( self::lang(), $placeID, array(
     392                                'customfield' => array(
     393                                    'Name'     => $$field_name,
     394                                    'Message'  => $$field_message,
     395                                    'Required' => $$field_required ? 'true' : 'false',
     396                                    'Type'     => $$field_type
     397                                )
     398                            ) );
     399                        }
    369400                    }
    370401                }
     
    482513                $reservationTime = $this->getReservationTime();
    483514
    484                 for ($i = 1; $i != CUSTOM_FIELDS; $i++) {
     515                $custom_fields_save_to = $this->GetOption( 'customfields_save_to' );
     516
     517                if ( $custom_fields_save_to === null || $custom_fields_save_to === CustomFieldsSaveTo::WPOptions ) {
     518                    // Get custom fields from wordpress options
     519                    $custom_fields = array();
     520                    for ( $i = 0; $i != CUSTOM_FIELDS; $i ++ ) {
    485521                    $field_name = 'field_' . $i . '_name';
    486522                    $field_type = 'field_' . $i . '_type';
     
    488524                    $field_message = 'field_' . $i . '_message';
    489525
    490                     $$field_name = $this->GetOption($field_name);
    491                     $$field_type = $this->GetOption($field_type);
    492                     $$field_required = $this->GetOption($field_required);
    493                     $$field_message = $this->GetOption($field_message);
     526                        $custom_fields[ $i ] = (object) array(
     527                            'Id'       => 0,
     528                            'Name'     => $this->GetOption( $field_name ),
     529                            'Type'     => $this->GetOption( $field_type ),
     530                            'Message'  => $this->GetOption( $field_message ),
     531                            'Required' => $this->GetOption( $field_required )
     532                        );
     533                    }
     534                } else {
     535                    $custom_fields = $this->redi->getCustomField( self::lang(), $placeID );
    494536                }
    495537            }
     
    740782        public function shortcode($attributes)
    741783        {
    742             //global $locale;
    743784            if (is_array($attributes) && is_array($this->options)) {
    744785                $this->options = array_merge($this->options, $attributes);
     
    746787            ob_start();
    747788            wp_enqueue_script('jquery');
    748             //wp_register_style('jquery_ui', null, array('jquery'));
    749789            wp_enqueue_style('jquery_ui');
    750790           
     
    850890            $maxTime = $this->GetOption('MaxTime', 1);
    851891            $thanks = $this->GetOption('Thanks');
    852 $manualReservation = $this->GetOption( 'ManualReservation');
     892            $manualReservation = $this->GetOption( 'ManualReservation');
    853893            $time_format_hours = self::dropdown_time_format();
    854 
    855             for ($i = 1; $i != CUSTOM_FIELDS; $i++) {
    856                 $field_name = 'field_' . $i . '_name';
    857                 $field_type = 'field_' . $i . '_type';
    858                 $field_required = 'field_' . $i . '_required';
    859                 $field_message = 'field_' . $i . '_message';
    860 
    861                 if (isset($this->options[$field_name])) {
    862                     if (isset($this->options[$field_name])) {
    863                         $$field_name = $this->options[$field_name];
    864                     }
    865                 }
    866 
    867                 if (isset($this->options[$field_type])) {
    868                     $$field_type = $this->options[$field_type];
    869                 }
    870 
    871                 if (isset($this->options[$field_required])) {
    872                     $$field_required = $this->options[$field_required];
    873                 }
    874 
    875                 if (isset($this->options[$field_message])) {
    876                     $$field_message = $this->options[$field_message];
    877                 }
    878             }
     894            $custom_fields_save_to = $this->GetOption( 'customfields_save_to' );
     895
     896            if ($custom_fields_save_to == CustomFieldsSaveTo::WPOptions) {
     897                // Get custom fields from wordpress options
     898                $custom_fields = array();
     899                for ( $i = 0; $i != CUSTOM_FIELDS; $i ++ ) {
     900                    $field_name     = 'field_' . $i . '_name';
     901                    $field_type     = 'field_' . $i . '_type';
     902                    $field_required = 'field_' . $i . '_required';
     903                    $field_message  = 'field_' . $i . '_message';
     904
     905                    $custom_fields[ $i ] = (object) array(
     906                        'Id'       => 0,
     907                        'Name'     => $this->GetOption( $field_name ),
     908                        'Type'     => $this->GetOption( $field_type ),
     909                        'Message'  => $this->GetOption( $field_message ),
     910                        'Required' => $this->GetOption( $field_required )
     911                    );
     912                }
     913            } else {
     914                $custom_fields = $this->redi->getCustomField( self::lang(), $placeID );
     915            }
     916
    879917            $hide_clock = false;
    880918            $persons = 1;
     
    11471185                    $currentTimeISO = date('Y-m-d H:i', current_time('timestamp'));
    11481186                    $comment = '';
    1149                     for ($i = 1; $i != CUSTOM_FIELDS; $i++) {
     1187                    for ( $i = 0; $i != CUSTOM_FIELDS; $i++ ) {
    11501188                        if (isset($_POST['field_' . $i])) {
    11511189
    11521190                            $field_type = 'field_' . $i . '_type';
    11531191
    1154                             if (isset($this->options[$field_type]) && $this->options[$field_type] === 'checkbox') {
    1155                                 $comment .= $this->options['field_' . $i . '_name'] . ': ';
    1156                                 $comment .= (self::GetPost('field_' . $i) === 'on') ? __('Yes',
    1157                                     'redi-booking') : __('No', 'redi-booking');
    1158                                 $comment .= '<br/>';
    1159                             } else {
    1160                                 if (!empty($_POST['field_' . $i])) {
    1161                                     $comment .= $this->options['field_' . $i . '_name'] . ': ';
    1162                                     $comment .= self::GetPost('field_' . $i) . '<br/>';
    1163                                 }
     1192                            if ( isset( $this->options[ $field_type ] )){                           
     1193                                $parameters[] = array(
     1194                                    'Name'  => $this->options[ 'field_' . $i . '_name' ],
     1195                                    'Type'  => strtolower( $this->options[ $field_type ]),
     1196                                    'Value' =>
     1197                                    $this->options[ $field_type ] === 'text' ?
     1198                                    self::GetPost( 'field_' . $i ) : (self::GetPost( 'field_' . $i ) === 'on' ? 'true' : 'false'));
    11641199                            }
    11651200                        }
     
    12601295            return json_decode(json_encode($object), true);
    12611296        }
     1297        private static function lang(){
     1298            return str_replace( '_', '-', get_locale());
     1299        }
    12621300    }
    12631301}
  • redi-restaurant-reservation/branches/newDesign/redi.php

    r1586737 r1689142  
    11<?php
    2 
    3 if (!defined('REDI_BOOKING_DEBUG')) {
    4     define( 'REDI_BOOKING_DEBUG', false );
    5 }
    6 if (!defined('USER')) {
    7     define('USER', 'User.svc/');
    8 }
    9 if (!defined('USERGET')) {
    10     define('USERGET', 'User.svc/get');
    11 }
    12 if (!defined('PLACE')) { // 'Place.svc/place' - for old version
    13     define('PLACE', 'Place.svc/');
    14 }
    15 if (!defined('SERVICE')) {
    16     define('SERVICE', 'Service.svc/');
    17 }
    18 if (!defined('CATEGORY')) {
    19     define('CATEGORY', 'Category.svc/');
    20 }
    21 if (!defined('RESERVATION')) {
    22     define ('RESERVATION', 'Reservation.svc/');
    23 }
    24 if(!defined('EMAILCONTENT')) {
    25     define('EMAILCONTENT','emailcontent.svc/');
    26 }
    27 if (!defined('POST')) {
    28     define('POST', 'POST');
    29 }
    30 if (!defined('GET')) {
    31     define('GET', 'GET');
    32 }
    33 if (!defined('PUT')) {
    34     define('PUT', 'PUT');
    35 }
    36 if (!defined('DELETE')) {
    37     define('DELETE', 'DELETE');
    38 }
    39 if (!defined('REDI_SUCCESS')) {
    40     define('REDI_SUCCESS', 'SUCCESS');
     2if ( ! defined( 'USER' ) ) {
     3    define( 'USER', 'User.svc/' );
     4}
     5if ( ! defined( 'USERGET' ) ) {
     6    define( 'USERGET', 'User.svc/get' );
     7}
     8if ( ! defined( 'PLACE' ) ) { // 'Place.svc/place' - for old version
     9    define( 'PLACE', 'Place.svc/' );
     10}
     11if ( ! defined( 'SERVICE' ) ) {
     12    define( 'SERVICE', 'Service.svc/' );
     13}
     14if ( ! defined( 'CATEGORY' ) ) {
     15    define( 'CATEGORY', 'Category.svc/' );
     16}
     17if ( ! defined( 'RESERVATION' ) ) {
     18    define( 'RESERVATION', 'Reservation.svc/' );
     19}
     20if ( ! defined( 'EMAILCONTENT' ) ) {
     21    define( 'EMAILCONTENT', 'emailcontent.svc/' );
     22}
     23if ( ! defined( 'CUSTOMFIELDS' ) ) {
     24    define( 'CUSTOMFIELDS', 'CustomFields.svc/' );
     25}
     26if ( ! defined( 'POST' ) ) {
     27    define( 'POST', 'POST' );
     28}
     29if ( ! defined( 'GET' ) ) {
     30    define( 'GET', 'GET' );
     31}
     32if ( ! defined( 'PUT' ) ) {
     33    define( 'PUT', 'PUT' );
     34}
     35if ( ! defined( 'DELETE' ) ) {
     36    define( 'DELETE', 'DELETE' );
     37}
     38if ( ! defined( 'REDI_SUCCESS' ) ) {
     39    define( 'REDI_SUCCESS', 'SUCCESS' );
    4140}
    4241if ( ! defined( 'REDI_BOOKING_API' ) ) {
    43     define('REDI_BOOKING_API', 'http://api.reservationdiary.eu/service/');
     42    define( 'REDI_BOOKING_API', 'http://api.reservationdiary.eu/service/' );
    4443}
    4544
    4645if ( ! defined( 'CUSTOM_FIELDS' ) ) {
    47 define('CUSTOM_FIELDS', 6);
     46    define( 'CUSTOM_FIELDS', 6 );
    4847}
    4948
    5049if ( ! class_exists( 'ReDiBookingApi' ) ) {
    5150    class ReDiBookingApi {
    52     private $ApiKey;
     51        private $ApiKey;
    5352
    5453        public function ReDiBookingApi( $ApiKey ) {
    55         $this->ApiKey = $ApiKey;
    56     }
    57 
    58     public function getReservationUrl($lang){
    59         return 'http://wp.reservationdiary.eu/' . $lang . '/' . $this->ApiKey . '/Reservation/Index';
    60     }
    61 
    62     public function getEmailContent($reservationID, $type, $params){
     54            $this->ApiKey = $ApiKey;
     55        }
     56
     57        public function deleteCustomField( $lang, $placeID, $customFieldID ) {
     58            return $this->request( REDI_BOOKING_API . CUSTOMFIELDS . $lang . '/' . $this->ApiKey . '/place/' . $placeID . '/customfield/' . $customFieldID, DELETE );
     59        }
     60
     61        public function updateCustomField( $lang, $placeID, $customFieldID, $params ) {
     62            return $this->request( REDI_BOOKING_API . CUSTOMFIELDS . $lang . '/' . $this->ApiKey . '/place/' . $placeID . '/customfield/' . $customFieldID, PUT,
     63                json_encode( self::unescape_array( $params ) ) );
     64        }
     65
     66        public function saveCustomField( $lang, $placeID, $params ) {
     67            return $this->request( REDI_BOOKING_API . CUSTOMFIELDS . $lang . '/' . $this->ApiKey . '/place/' . $placeID, POST,
     68                json_encode( self::unescape_array( $params ) ) );
     69        }
     70
     71        public function getCustomField( $lang, $placeID ) {
     72            return $this->request( REDI_BOOKING_API . CUSTOMFIELDS . $lang . '/' . $this->ApiKey . '/place/' . $placeID, GET );
     73        }
     74
     75        public function getBlockingDates( $lang, $categoryID, $params ) {
     76            return $this->request( REDI_BOOKING_API . DATES . $lang . '/' . $this->ApiKey . '/' . $categoryID, GET, self::strParams( $params ) );
     77        }
     78
     79        public function getReservationUrl( $lang ) {
     80            return 'http://wp.reservationdiary.eu/' . $lang . '/' . $this->ApiKey . '/Reservation/Index';
     81        }
     82
     83        public function getEmailContent( $reservationID, $type, $params ) {
    6384            return $this->request( REDI_BOOKING_API . EMAILCONTENT . $this->ApiKey . '/' . $reservationID . '/ClientReservation' . $type,
    6485                GET, $params );
    65     }
    66 
    67     public function cancelReservationByClient( $params ) {
    68             return $this->request( REDI_BOOKING_API . RESERVATION . $this->ApiKey . '/cancelByClient' . self::strParams( $params ), DELETE);
    69     }
    70 
    71     public function cancelReservation( $params ) {
     86        }
     87
     88        public function cancelReservationByClient( $params ) {
     89            return $this->request( REDI_BOOKING_API . RESERVATION . $this->ApiKey . '/cancelByClient' . self::strParams( $params ), DELETE );
     90        }
     91
     92        public function cancelReservation( $params ) {
    7293            return $this->request( REDI_BOOKING_API . RESERVATION . $this->ApiKey . '/cancelByProvider' . self::strParams( $params ), DELETE );
    73     }
     94        }
    7495
    7596        public function createReservation( $categoryID, $params ) {
    7697            return $this->request( REDI_BOOKING_API . RESERVATION . $this->ApiKey . '/' . $categoryID, POST,
    7798                json_encode( self::unescape_array( $params ) ) );
    78     }
     99        }
    79100
    80101        public function query( $categoryID, $params ) {
    81102            return $this->request( REDI_BOOKING_API . RESERVATION . $this->ApiKey . '/' . $categoryID . '/Person',
    82103                GET, $params );
    83     }
     104        }
    84105
    85106        public function createCategory( $placeID, $params ) {
    86107            return $this->request( REDI_BOOKING_API . CATEGORY . $this->ApiKey . '/' . $placeID, POST,
    87108                json_encode( self::unescape_array( $params ) ) );
    88     }
     109        }
    89110
    90111        public function getServices( $categoryID ) {
    91         return $this->request(REDI_BOOKING_API.SERVICE.$this->ApiKey.'/'.$categoryID.'/Person', GET);
    92     }
     112            return $this->request( REDI_BOOKING_API . SERVICE . $this->ApiKey . '/' . $categoryID . '/Person', GET );
     113        }
    93114
    94115        public function deleteServices( $ids ) {
    95116            return $this->request( REDI_BOOKING_API . SERVICE . $this->ApiKey . '?serviceID=' . join( ',', $ids ),
    96117                DELETE );
    97     }
     118        }
    98119
    99120        public function setServiceTime( $categoryID, $timeSet ) {
    100         return $this->request(REDI_BOOKING_API.CATEGORY.$this->ApiKey.'/'.$categoryID.'/time',
    101             PUT,
    102             json_encode(self::unescape_array(array ('timeSet' => $timeSet))));
    103     }
     121            return $this->request( REDI_BOOKING_API . CATEGORY . $this->ApiKey . '/' . $categoryID . '/time',
     122                PUT,
     123                json_encode( self::unescape_array( array( 'timeSet' => $timeSet ) ) ) );
     124        }
    104125
    105126        public function getServiceTime( $categoryID ) {
    106         return $this->request(REDI_BOOKING_API.CATEGORY.$this->ApiKey.'/'.$categoryID.'/time', GET);
    107     }
     127            return $this->request( REDI_BOOKING_API . CATEGORY . $this->ApiKey . '/' . $categoryID . '/time', GET );
     128        }
    108129
    109130        public function createService( $categoryID, $params ) {
    110131            return $this->request( REDI_BOOKING_API . SERVICE . $this->ApiKey . '/' . $categoryID, POST,
    111132                json_encode( self::unescape_array( $params ) ) );
    112     }
     133        }
    113134
    114135        public function userGetError() {
    115         return $this->request(REDI_BOOKING_API.USERGET);
    116     }
     136            return $this->request( REDI_BOOKING_API . USERGET );
     137        }
    117138
    118139        public function createUser( $params ) {
    119         return $this->request(REDI_BOOKING_API.USER, POST, json_encode(self::unescape_array($params)));
    120     }
     140            return $this->request( REDI_BOOKING_API . USER, POST, json_encode( self::unescape_array( $params ) ) );
     141        }
    121142
    122143        public function setPlace( $placeID, $params ) {
    123144            return $this->request( REDI_BOOKING_API . PLACE . $this->ApiKey . '/' . $placeID, PUT,
    124145                json_encode( self::unescape_array( $params ) ) );
    125     }
     146        }
    126147
    127148        public function createPlace( $params ) {
    128149            return $this->request( REDI_BOOKING_API . PLACE . $this->ApiKey, POST,
    129150                json_encode( self::unescape_array( $params ) ) );
    130     }
     151        }
    131152
    132153        public function shiftsStartTime( $categoryID, $params ) {
    133154            return $this->request( REDI_BOOKING_API . CATEGORY . $this->ApiKey . '/' . $categoryID . '/shiftsStartTime',
    134                 GET, $params );
    135     }
     155                GET, $params );
     156        }
    136157
    137158        public function availabilityByDay( $categoryID, $params ) {
    138159            return $this->request( REDI_BOOKING_API . RESERVATION . $this->ApiKey . '/' . $categoryID . '/availabilityByDay/Person',
    139160                GET, $params );
    140     }
     161        }
    141162
    142163        public function availabilityByShifts( $categoryID, $params ) {
    143164            return $this->request( REDI_BOOKING_API . RESERVATION . $this->ApiKey . '/' . $categoryID . '/availabilityByShifts/Person',
    144                 GET, $params );
    145     }
     165                GET, $params );
     166        }
    146167
    147168        public function getPlace( $placeID ) {
    148         return $this->request(REDI_BOOKING_API.PLACE.$this->ApiKey.'/'.$placeID, GET);
    149     }
     169            return $this->request( REDI_BOOKING_API . PLACE . $this->ApiKey . '/' . $placeID, GET );
     170        }
    150171
    151172        public function getPlaceCategories( $placeID ) {
    152         return $this->request(REDI_BOOKING_API.PLACE.$this->ApiKey.'/'.$placeID.'/categories', GET);
    153     }
     173            return $this->request( REDI_BOOKING_API . PLACE . $this->ApiKey . '/' . $placeID . '/categories', GET );
     174        }
    154175
    155176        public function getPlaces() {
    156         return $this->request(REDI_BOOKING_API.PLACE.$this->ApiKey, GET);
    157     }
     177            return $this->request( REDI_BOOKING_API . PLACE . $this->ApiKey, GET );
     178        }
    158179
    159180        public function setApiKey( $ApiKey ) {
    160         $this->ApiKey = $ApiKey;
    161     }   
    162 
    163         private static function unescape_array( $array ) {
    164         $unescaped_array = array();
    165             foreach ( $array as $key => $val ) {
    166                 if ( is_array( $val ) ) {
    167                 $unescaped_array[$key] = self::unescape_array($val);
    168                 } else {
    169                 $unescaped_array[$key] = stripslashes($val);
    170             }
    171         }
    172         return $unescaped_array;
    173     }
    174 
    175     private static function strParams( $params ) {
     181            $this->ApiKey = $ApiKey;
     182        }
     183
     184        private static function strParams( $params ) {
    176185            $url_param = '';
    177186            $first     = 0;
     
    186195        }
    187196
    188     private function request( $url, $method = GET, $params = null ) {
    189         $request = new WP_Http;
    190         $curTime = microtime( true );
    191 
    192         $output  = $request->request(
    193             $url,
    194             array(
    195                 'method'  => $method,
    196                 'body'    => $params,
    197                 'headers' => array(
    198                     'Content-Type' => 'application/json; charset=utf-8'
    199                 )
    200             ) );
    201         if ( is_wp_error( $output ) ) {
    202             return array(
    203                 'request_time' => round( microtime( true ) - $curTime, 3 ) * 1000,
     197        private static function unescape_array( $array ) {
     198            $unescaped_array = array();
     199            foreach ( $array as $key => $val ) {
     200                if ( is_array( $val ) ) {
     201                    $unescaped_array[ $key ] = self::unescape_array( $val );
     202                } else {
     203                    $unescaped_array[ $key ] = stripslashes( $val );
     204                }
     205            }
     206
     207            return $unescaped_array;
     208        }
     209
     210
     211        private function request( $url, $method = GET, $params = null ) {
     212            $request = new WP_Http;
     213            $curTime = microtime( true );
     214
     215            $output = $request->request(
     216                $url,
     217                array(
     218                    'method'  => $method,
     219                    'body'    => $params,
     220                    'headers' => array(
     221                        'Content-Type' => 'application/json; charset=utf-8'
     222                    )
     223                ) );
     224            if ( is_wp_error( $output ) ) {
     225                return array(
     226                    'request_time' => round( microtime( true ) - $curTime, 3 ) * 1000,
    204227                    'Error'        => __( 'Online reservation service is not available at this time. Try again later or contact us directly.',
    205228                        'redi-booking' ),
    206                 'Wp-Error' => $output->errors
    207             );
    208         }
    209 
     229                    'Wp-Error'     => $output->errors
     230                );
     231            }
    210232        if ( $output['response']['code'] != 200 && $output['response']['code'] != 400 ) {
    211233                return array(
     
    214236                );
    215237        }
    216         $output = $output['body'];
    217 
    218 
    219         // convert response
    220         $output = (array) json_decode( $output );
    221         if ( REDI_BOOKING_DEBUG ){
    222             $output['debug'] = array
    223             (
    224                 'method' => $method,
    225                 'params' => self::p( $params, true ),
    226                 'url'    => self::p( $url ,true )
    227             );
    228         }
    229 
    230         return $output;
    231     }
    232 
    233     public static function d( $object, $color = true ) {
    234         if ( REDI_BOOKING_DEBUG ) {
    235             if ( ! $color ) {
    236                 echo '<pre>';
    237                 var_dump($object);
    238                 echo '<pre>';
    239 
    240                 return;
    241             }
    242             $result = highlight_string( "<?php\n" . print_r( $object, true ), true );
     238            $output = $output['body'];
     239
     240
     241            // convert response
     242            $output = (array) json_decode( $output );
     243            if ( REDI_BOOKING_DEBUG ) {
     244                $output['debug'] = array
     245                (
     246                    'method' => $method,
     247                    'params' => self::p( $params, true ),
     248                    'url'    => self::p( $url, true )
     249                );
     250            }
     251
     252            return $output;
     253        }
     254
     255        public static function d( $object, $color = true ) {
     256            if ( REDI_BOOKING_DEBUG ) {
     257                if ( ! $color ) {
     258                    echo '<pre>';
     259                    var_dump( $object );
     260                    echo '<pre>';
     261
     262                    return;
     263                }
     264                $result = highlight_string( "<?php\n" . print_r( $object, true ), true );
    243265                echo '<pre style="text-align: left;">' . preg_replace( '/&lt;\\?php<br \\/>/', '', $result,
    244266                        1 ) . '</pre><br />';
    245         }
    246 
     267            }
     268
     269        }
     270
     271        public static function p( $object ) {
     272
     273            if ( REDI_BOOKING_DEBUG ) {
     274                return var_export( $object, true );
     275            }
     276        }
    247277    }
    248 
    249     public static function p( $object ) {
    250         if ( REDI_BOOKING_DEBUG ) {
    251             return var_export( $object, true );
    252     }
    253 }
    254 }
    255 }
     278}
  • redi-restaurant-reservation/branches/newDesign/templates/admin.php

    r1598865 r1689142  
    235235        <p class="description">
    236236            <?php _e('Custom fields are meant to allow users define additional fields for collecting more information from customers. You can choose the name of the field, type of field, the constraint whether it is a required field or not and the error message for the required field.', 'redi-booking') ?><br/>
    237             <b style="color: red"><?php _e('NOTE: Name, Email and Phone are required fields of reservation form and does not need to be defined here as custom fields.', 'redi-booking') ?></b>
     237            <b style="color: red"><?php _e('NOTE: Name, Email and Phone are required fields of reservation form and do not need to be defined here as custom fields.', 'redi-booking') ?></b>
    238238        </p>
    239239
    240         <table class="form-table" style="width: 80%;">
     240        <table class="form-table" style="width: 90%; text-align: center;">
    241241            <thead>
    242242                <tr>
     
    261261                        </label>
    262262                    </th>
     263                    <th>
     264
     265                    </th>
    263266                </tr>
    264267            </thead>
    265             <?php for($i = 1; $i != CUSTOM_FIELDS; $i++):?>
     268
     269            <?php  for ( $i = 0; $i != CUSTOM_FIELDS; $i++ ):
     270                if ( ! isset( $custom_fields[ $i ] ) ) {
     271                    $custom_fields[ $i ] = (object) array(
     272                        'Id'       => 0,
     273                        'Name'     => '',
     274                        'Type'     => 'text',
     275                        'Message'  => '',
     276                        'Required' => false
     277                    );
     278                }
     279                $custom_field = $custom_fields[ $i ];
     280            ?>
     281            <?php $field_id = ('field_'.$i.'_id');?>
     282
    266283            <tr>
    267284                <td>
     285                    <input type="hidden" id="<?php echo $field_id;?>" name="<?php echo $field_id;?>" value="<?php  echo $custom_field->Id ?>" />
    268286                    <?php $field_name=('field_'.$i.'_name'); ?>
    269                     <input type="text" name="<?php echo $field_name; ?>" value="<?php echo $$field_name; ?>"/>
    270                 </td>
    271                 <td>
     287                    <input type="text" id="<?php echo $field_name; ?>" name="<?php echo $field_name; ?>" value="<?php echo $custom_field->Name; ?>"/>
     288                </td>
     289                <td style="vertical-align: top;">
    272290                    <?php $field_type=('field_'.$i.'_type'); ?>
    273                     <select name="<?php echo $field_type; ?>">
    274                         <option value="textbox" <?php if ($$field_type === 'textbox'):?>selected="selected"<?php endif?>>TextBox</option>
    275                         <option value="checkbox" <?php if ($$field_type === 'checkbox'):?>selected="selected"<?php endif?>>Checkbox</option>
     291                    <select onchange="set_name('<?php echo $field_name; ?>',this.options[this.selectedIndex].value);" class="field_type" name="<?php echo $field_type; ?>" id="<?php echo $field_type; ?>">
     292                        <option value="text" <?php if ($custom_field->Type === 'text'):?>selected="selected"<?php endif?>><?php _e('Text field', 'redi-booking'); ?></option>
     293                        <option value="checkbox" <?php if ($custom_field->Type === 'checkbox'):?>selected="selected"<?php endif?>><?php _e('Check box', 'redi-booking'); ?></option>
    276294                    </select>
    277295                </td>
    278296                <td>
    279297                    <?php $field_required=('field_'.$i.'_required'); ?>
    280                     <input type="checkbox" name="<?php echo $field_required; ?>" <?php if ($$field_required): ?>checked="checked"<?php endif?>>
     298                    <input type="checkbox" id="<?php echo $field_required; ?>" name="<?php echo $field_required; ?>" <?php if ($custom_field->Required): ?>checked="checked"<?php endif?>>
    281299                </td>
    282300                <td>
    283301                    <?php $field_message=('field_'.$i.'_message'); ?>
    284                     <input type="text" name="<?php echo $field_message;?>" value="<?php echo $$field_message; ?>" style="width:300px;">
     302                    <input type="text" id="<?php echo $field_message;?>" name="<?php echo $field_message;?>" value="<?php echo $custom_field->Message ?>" style="width:250px;">
     303                </td>
     304                <td>
     305                    <a onclick="jQuery('#<?php echo $field_name; ?>').val(''); jQuery('#<?php echo $field_message; ?>').val(''); jQuery('#<?php echo $field_type; ?>').val('text'); jQuery('#<?php echo $field_required; ?>').attr('checked', false);">clear</a>
    285306                </td>
    286307            </tr>
    287308            <?php endfor; ?>
    288309        </table>
     310        <!-- /custom fields-->
    289311        <br/>
    290312        <!-- /custom fields-->
  • redi-restaurant-reservation/branches/newDesign/templates/frontend.php

    r1653008 r1689142  
    297297            <br/>
    298298            <!-- custom fields -->
    299             <?php for ( $i = 1; $i != 6; $i ++ ): ?>
    300                 <?php $field_name = 'field_' . $i . '_name'; ?>
    301                 <?php $field_required = 'field_' . $i . '_required'; ?>
    302                 <?php $field_type = 'field_' . $i . '_type'; ?>
    303                 <?php $field_message = 'field_' . $i . '_message'; ?>
    304                 <?php if ( isset( $$field_name ) && ! empty( $$field_name ) ): ?>
     299            <?php $i = 0; ?>
     300            <?php foreach ( $custom_fields as $custom_field ):?>
     301            <?php $i++; ?>
     302                <?php if(isset($custom_field->Name) && !empty($custom_field->Name)):?>
    305303                    <div class="f_select2">
    306304                        <div class="f_input_box">
    307                             <span class="selectArrow6 <?php if ( isset( $$field_required ) && $$field_required ): ?>required<?php endif; ?>"></span>
    308                             <?php switch ( $$field_type ):
    309                                 case 'checkbox':
    310                                     ?>
     305                            <span class="selectArrow6 <?php if(isset($custom_field->Required) && $custom_field->Required): ?>required<?php endif; ?>"></span>
     306                            <?php
     307                    switch($custom_field->Type):
     308                        case 'checkbox':?>
    311309                                    <span class="checkbox_field">
    312310                        <input type="checkbox" value="" name="field_<?php echo $i; ?>"
    313311                               id="field_<?php echo $i; ?>"
    314                                class="<?php if ( isset( $$field_required ) && $$field_required ): ?>field_required<?php endif; ?>"/>
     312                               class="<?php if ( isset( $custom_field->Required ) && $custom_field->Required ): ?>field_required<?php endif; ?>"/>
    315313                        <label for="field_<?php echo $i; ?>">
    316                             <?php echo $$field_name; ?>
     314                            <?php echo $custom_field->Name; ?>
    317315                        </label>
    318316                    </span>
     
    321319                                    ?>
    322320                                    <input type="text"
    323                                            placeholder="<?php echo $$field_name; ?>" value=""
     321                                           placeholder="<?php echo $custom_field->Name; ?>" value=""
    324322                                           name="field_<?php echo $i; ?>" id="field_<?php echo $i; ?>"
    325                                            class="text_field <?php if ( isset( $$field_required ) && $$field_required ): ?>field_required<?php endif; ?>"/>
     323                                           class="text_field <?php if ( isset( $custom_field->Required ) && $custom_field->Required ): ?>field_required<?php endif; ?>"/>
    326324                                    <?php break; endswitch; ?>
    327325                        </div>
    328326                        </div>
    329                         <?php if ( isset( $$field_required ) && $$field_required ): ?>
     327                        <?php if ( isset( $custom_field->Required ) && $custom_field->Required ): ?>
    330328                            <div id="<?php echo 'field_' . $i . '_message'; ?>" style="display:none; text-align: center;">
    331329                                <span class="validation_error">
    332                                     <?php echo ( ! empty( $$field_message ) ) ? $$field_message : ( _e( 'Custom field is required', 'redi-booking' ) ); ?>
     330                                    <?php echo ( ! empty( $custom_field->Message ) ) ? $custom_field->Message : ( _e( 'Custom field is required', 'redi-booking' ) ); ?>
    333331                                </span>
    334332                            </div>
     
    337335                    <br/>
    338336                <?php endif; ?>
    339             <?php endfor; ?>
     337            <?php endforeach; ?>
    340338            <!-- /custom fields -->
    341339            <br/>
Note: See TracChangeset for help on using the changeset viewer.