public function getDependenciesOf($strSidebarID, $arrHierarchyBase = null)
 {
     // since 1.1.7.2
     // Similar to the above GetDependencies() method but this one only checks the dependencies of the given sidebar.
     // This is used by the core class before it renders the widget box output in case a dependency conflict is happening.
     // Generate the base hierarchy array from the widget options.
     if (is_null($arrHierarchyBase)) {
         $oWO = new ResponsiveColumnWidgets_WidgetOptions();
         $arrHierarchyBase = $oWO->GetHierarchyBase();
         unset($oWO);
         // for PHP below 5.3
     }
     $arrDependencies = $this->GetFlatternChildWidgetBoxes($strSidebarID, $arrHierarchyBase);
     if (is_null($arrDependencies)) {
         // If null, a dependency conflict occurred. So add the parsing sidebar ID to the parent sidebar.
         $arrDependencies = array($strSidebarID);
     }
     return $arrDependencies;
 }
    public function form($arrInstance)
    {
        /*
         * Variables - use uniqid() to generate a unique ID to avoid the same ID being inserted among other widgets dropped onto different sidebar boxes.
         */
        // Aboid undefined index warnings.
        $arrInstance = $arrInstance + array('sidebarid_selected' => null, 'sidebarid_parent' => null);
        // For the select tag.
        $strID_SidebarIDSelected = $this->get_field_id('sidebarid_selected');
        $strName_SidebarIDSelected = $this->get_field_name('sidebarid_selected');
        // the string "sidebarid_selected" will be the key for the field and passed as the input array key to the update() method.
        // For the option tag.
        $strID_Selector = $strID_SidebarIDSelected . '_' . uniqid();
        $strClass_Option = $strID_Selector;
        // For the hidden input tag that indicates the sidebar ID of the one to which the selected sidebar belongs.
        $strID_SidebarParent = $this->get_field_id('sidebarid_parent') . '_' . uniqid();
        // the string "sidebarid" will be the key for the field and passed as the input array key to the update() method.
        $strName_SidebarParent = $this->get_field_name('sidebarid_parent');
        // the string "sidebarid" will be the key for the field and passed as the input array key to the update() method.
        // Create the array for the hierarchy reference.
        $oSH = new ResponsiveColumnWidgets_SidebarHierarchy();
        $arrDependencies = $oSH->GetDependencies();
        unset($oSH);
        // make sure the object is released.
        // echo 'Sidebar Hierarchy: <br />'
        // . $this->DumpArray( $arrDependencies );
        $oWO = new ResponsiveColumnWidgets_WidgetOptions();
        $arrWidgetOptions = $oWO->GetRegisteredWidgetOptionsByBaseID();
        unset($oWO);
        // make sure the object is released.
        // echo 'Widget Options: <br />'
        // . '<div style="font-size: 80%; margin-left: 0px; padding-left: 0px">'
        // . $this->DumpArray( $arrWidgetOptions )
        // . '</div>';
        // echo 'This Widget ID: ' . $this->id . '<br />';
        // Set the container sidebar ID - note that this will not work ( a null will be assigned ) when the widget is dropped for the first time. ( works after saving the form options. )
        $this->strContainerSidebarID = $this->GetContainerSidebarID();
        // echo 'Parent Sidebar ID: ' . $this->strContainerSidebarID . '<br />';
        ?>
        <p>    
    
            <input type="hidden" name="<?php 
        echo $strName_SidebarParent;
        ?>
" id="<?php 
        echo $strID_SidebarParent;
        ?>
" class="<?php 
        echo $this->strClassSelector_ContainerSidebarID;
        ?>
" value="<?php 
        echo $this->strContainerSidebarID;
        ?>
" />
            <label for="<?php 
        echo $strID_Selector;
        ?>
">
                <?php 
        _e('Select Sidebar', 'responsive-column-widgets');
        ?>
:
            </label>
            <br />
            <select name="<?php 
        echo $strName_SidebarIDSelected;
        ?>
" id="<?php 
        echo $strID_Selector;
        ?>
" class="<?php 
        echo $this->strClassSelectorFormSelect;
        ?>
">
                <?php 
        // the default non-select item.
        echo '<option class="' . $strClass_Option . ' ' . $this->strClassSelectorFormOption . '" value="">' . '-------- ' . __('Select a sidebar', 'responsive-column-widgets') . ' --------' . '</option>';
        foreach ($GLOBALS['wp_registered_sidebars'] as $arrSidebar) {
            $bDisabled = false;
            // wp_inactive_widgets is for the Inactive Widgets section box in the admin widget page. So do nothing.
            if ($arrSidebar['id'] == 'wp_inactive_widgets') {
                continue;
            }
            if (in_array('inactive-sidebar', explode(' ', $arrSidebar['class']))) {
                continue;
            }
            // If the parsing sidebar ID is the same as the container sidebar ID, disable it.
            if ($arrSidebar['id'] == $this->strContainerSidebarID) {
                $bDisabled = true;
            }
            // If the parsing sidebar ID matches this widget's parent (container) sidebar ID, disable it.
            // The $this->id property is defined in the WP_Widget class ( the parent class of this class ) and the id properties is the widget id of this widget instance.
            if (isset($arrWidgetOptions[$this->id]['sidebarid_parent']) && $arrWidgetOptions[$this->id]['sidebarid_parent'] == $arrSidebar['id']) {
                $bDisabled = true;
            }
            // If the parsing sidebar ID ( the candidate to be a child sidebar ) has this container sidebar as its child, then disable it.
            if (isset($arrDependencies[$arrSidebar['id']]) && in_array($this->strContainerSidebarID, $arrDependencies[$arrSidebar['id']])) {
                $bDisabled = true;
            }
            // If the container sidebar    ID has the parsing sidebar ID as its dependency, disable it.
            // This should not be commented out but currently the JavaScript scripts of this plugin are not able to enable this item
            // when the position of widget is changed. Until the script to fix it is added, let it being commented out.
            // if ( isset( $arrDependencies[ $this->strContainerSidebarID ] ) && in_array( $arrSidebar['id'], $arrDependencies[ $this->strContainerSidebarID ] ) )
            // $bDisabled = true;
            echo '<option class="' . $strClass_Option . ' ' . $this->strClassSelectorFormOption . '" value="' . esc_attr($arrSidebar['id']) . '" ' . ($arrSidebar['id'] == $arrInstance['sidebarid_selected'] ? 'selected="Selected"' : '') . ($bDisabled ? ' disabled=Disabled' : '') . '>' . ucwords($arrSidebar['name']) . '</option>';
        }
        ?>
            </select>
        </p>
        
        <?php 
        if (version_compare(get_bloginfo('version'), '3.6', "<")) {
            ?>
        <script type="text/javascript" class="responsive-column-widgets-widget-registration-script" >

            var select = jQuery( "select#<?php 
            echo $strID_Selector;
            ?>
" );    
            var container_sidebar_id = select.closest( ".widgets-sortables" ).attr( "id" ); 
            var selects = jQuery( "select.<?php 
            echo $this->strClassSelectorFormSelect;
            ?>
" );

            console.log( '(RCW Log) The plugin widget form has been rendered.' );
            if ( typeof container_sidebar_id !== 'undefined' && container_sidebar_id != 'wp_inactive_widgets' ) {
                
                console.log( 
                    '(RCW Log) Container Sidebar ID: ' + container_sidebar_id + '\n' +
                    'Widget ID: <?php 
            echo $this->id;
            ?>
'                 
                );
                
                // Set the container sidebar ID to the hidden input field. This is important for the update() method to update the form options.
                jQuery( "input#<?php 
            echo $strID_SidebarParent;
            ?>
" ).val( container_sidebar_id );    
                
                ResponsiveColumnWidgets_DoAjaxRequestForWidgetRegistration();
                
            }
                        
            // When the widget is drag'n-dropped,
            var container_divs = selects.closest( "div.widgets-sortables" );
        
            // (Re)Hook the widget drop event.                
            // Somehow the live() method causes syntax errors so use the bind method.
            container_divs.unbind( 'sortstop sortreceive' );    // unbind previous event hooks.
            container_divs.bind( 'sortstop sortreceive', function( event, ui ){
                ResponsiveColumnWidgets_WidgetDropEvent( event, ui );
            });
    
        </script>
        <?php 
        }
        ?>
        <?php 
        if (version_compare(get_bloginfo('version'), '3.6', ">=")) {
            ?>
        <script type="text/javascript" class="responsive-column-widgets-widget-registration-script" >
        
            var select = jQuery( "select#<?php 
            echo $strID_Selector;
            ?>
" );        
            var container_sidebar_id = select.closest( ".widgets-sortables" ).attr( "id" ); 
            var selects = jQuery( "select.<?php 
            echo $this->strClassSelectorFormSelect;
            ?>
" );

            console.log( '(RCW Log) The plugin widget form has been rendered.' );
            if ( typeof container_sidebar_id !== 'undefined' && container_sidebar_id != 'wp_inactive_widgets' ) {
                
                console.log( 
                    '(RCW Log) Container Sidebar ID: ' + container_sidebar_id + '\n' +
                    'Widget ID: <?php 
            echo $this->id;
            ?>
'                 
                );
                
                // Set the container sidebar ID to the hidden input field. This is important for the update() method to update the form options.
                jQuery( "input#<?php 
            echo $strID_SidebarParent;
            ?>
" ).val( container_sidebar_id );    
                
                ResponsiveColumnWidgets_DoAjaxRequestForWidgetRegistration();
                
            }        
                    
        </script>
        <?php 
        }
    }
 /**
  * Check sidebar dependency conflicts.
  * 
  * @since       1.1.7.3
  */
 protected function isDependencyConflict($strSidebarID)
 {
     if (!isset($this->arrSidebarHierarchies)) {
         // 1.1.7.3+ Store the sidebar hierarchy array in a property.
         $oWO = new ResponsiveColumnWidgets_WidgetOptions();
         $this->arrSidebarHierarchies = $oWO->GetHierarchyBase();
         unset($oWO);
         // for PHP below 5.3
     }
     $oSH = new ResponsiveColumnWidgets_SidebarHierarchy();
     $arrDependencies = $oSH->getDependenciesOf($strSidebarID, $this->arrSidebarHierarchies);
     unset($oSH);
     // for PHP below 5.3.
     if (isset($this->arrSidebarHierarchies['']) || in_array($strSidebarID, $arrDependencies)) {
         return true;
     }
     return false;
 }