<?php
// Default options values //
$sa_options = array(
    'footer_copyright' => '&copy; Copyright ' . date('Y') . '',
        /****** Options Tab 1 ******/
    'hpannerlink' => get_bloginfo('url'),
    'hbannerpic' => get_bloginfo('template_url') . '/images/490ads.png',

    'ppannerlink' => get_bloginfo('url'),
    'pbannerpic' => get_bloginfo('template_url') . '/images/Logo_468_60.gif',
        /****** Options Tab 1 ******/


    'layout_view' => 'fixed',
    'author_credits' => true
);

if (is_admin()) { // Load only if we are viewing an admin page

    function sa_register_settings()
    {
        // Register settings and call sanitation functions
        register_setting('sa_theme_options', 'sa_options', 'sa_validate_options');
    }

    add_action('admin_init', 'sa_register_settings');

    // Store categories in array
    $sa_categories[0] = array(
    'value' => 0,
    'label' => ''
);
    $sa_cats = get_categories();
    $i = 1;
    foreach ($sa_cats as $sa_cat) {
        $sa_categories[$sa_cat->cat_ID] = array(
        'value' => $sa_cat->cat_ID,
        'label' => $sa_cat->cat_name
    );
        $i++;
    }


    //store slide total count in array ddd
    $slide_count = array( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 );



    // Store layouts views in array
    $sa_layouts = array(
    'fixed' => array(
        'value' => 'fixed',
        'label' => 'Fixed Layout'
    ),
    'fluid' => array(
        'value' => 'fluid',
        'label' => 'Fluid Layout'
    ),
);

    function sa_theme_options()
    {
        // Add theme options page to the addmin menu
        add_menu_page('Theme Options', 'Theme Options', 'edit_theme_options', 'theme_options', 'sa_theme_options_page');
    }

    add_action('admin_menu', 'sa_theme_options');

    // Function to generate options page
    function sa_theme_options_page()
    {
        global $sa_options, $sa_categories, $sa_layouts;

        if (! isset($_REQUEST['updated'])) {
            $_REQUEST['updated'] = false;
        } // This checks whether the form has just been submitted.?>

<script src="<?php bloginfo('template_directory'); ?>/panel/jquery-1.7.1.min.js" type="text/javascript"></script>
<script src="<?php bloginfo('template_directory'); ?>/panel/ajax_form.js"></script>
<link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/panel/adminpanel_css.css" type="text/css" />
<div id="CPanel_Content">
  <div class="CPanel_Content_Right">
    <div id="Logo"></div>
    <ul>
      <li><a href="#cp-1" title="">أعدادات القالب</a></li>
    </ul>
    <div id="Ro2ia"><a href="https://www.spot4h.com" target="_blank" title="تصميم وتنفيذ مؤسسة سبوت لخدمات الويب المكتاملة">تصميم وتنفيذ <span>مؤسسة سبوت</span></a></div>
    <a href="javascript:cp_up();" class="cp_up"> </a> </div>
  <!--/Right-->
  <div class="CPanel_Content_Left">

<?php if (false !== $_REQUEST['updated']) {
            ?>
<div class="updated fade" id="message"><p><strong><?php _e('تم تحديث البيانات بنجاح'); ?></strong></p></div>';
<?php
        }; // If the form has just been submitted, this shows the notification?>
    <form method="post" action="options.php" id="myForm">
<?php $settings = get_option('sa_options', $sa_options); ?>

	<?php settings_fields('sa_theme_options');
        /* This function outputs some hidden fields required by the form,
        including a nonce, a unique number used to ensure the form has been submitted from the admin page
        and not somewhere else, very important for security */ ?>
      <!-- tab_1 -->
      <div class="cp-content" id="cp-1">
        <h2>أعدادات الموقع</h2>

        <table border="0" width="100%" id="tb1">


            <tr>
              <td><label for="hpannerlink">رابط بنر الهيدر</label></td>
              <td><input name="sa_options[hpannerlink]" style="direction:rtl; text-align:right;" id="hpannerlink"  class="text_box" value="<?php  esc_attr_e($settings['hpannerlink']); ?>" /></td>
            </tr>

            <tr>
              <td><label for="hbannerpic">صورة بنر الهيدر</label></td>
              <td><input name="sa_options[hbannerpic]" style="direction:rtl; text-align:right;" id="hbannerpic"  class="text_box" value="<?php  esc_attr_e($settings['hbannerpic']); ?>" /></td>
            </tr>


            <tr>
              <td><label for="ppannerlink">رابط بنر التدوينات</label></td>
              <td><input name="sa_options[ppannerlink]" style="direction:rtl; text-align:right;" id="ppannerlink"  class="text_box" value="<?php  esc_attr_e($settings['ppannerlink']); ?>" /></td>
            </tr>

            <tr>
              <td><label for="pbannerpic">صورة بنر التدوينات</label></td>
              <td><input name="sa_options[pbannerpic]" style="direction:rtl; text-align:right;" id="pbannerpic"  class="text_box" value="<?php  esc_attr_e($settings['pbannerpic']); ?>" /></td>
            </tr>




          </table>

       </div>
      <!--/ tab_1 -->








<input type="submit" class="cp_save" name="cp_save" value="<?php _e('حفظ الاعدادات') ?>" />

    </form>
    <p class="loding_submit">جارى حفظ الإعدادات</p>
    <p class="add_done">تم حفظ الإعدادات بنجاح</p>
</div>
  <script type="text/javascript">
  //
jQuery(document).ready(function() {
//
$(".cp-content").hide(); //Hide all content
$(".CPanel_Content_Right ul li:first").addClass("cp-active").show();
$(".cp-content:first").show(); //Show first tab content
$(".CPanel_Content_Right ul li").click(function() {
$(".CPanel_Content_Right ul li").removeClass("cp-active");
$(this).addClass("cp-active"); //Add "active" class to selected tab
$(".cp-content").hide(); //Hide all tab content
var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value
$(activeTab).fadeIn(300); //Fade in the active content
return false;
});
//
/*$(".CPanel_Content_Right ul li a").hover(function() {
$(this).stop().animate({paddingRight:"7"},200);
},function(){
$(this).stop().animate({paddingRight:"0"},350);
});*/
//
// shows on clicking the noted link
$('h2').click(function() {
$(this).toggleClass("close");
$(this).next("table").fadeToggle(300);
return false;
});
//
$('.cp_save').click(function(){
$('.loding_submit').fadeIn(500);
});
//
$('#myForm').ajaxForm(function() {
$('.loding_submit').fadeOut(500);
$('.add_done').fadeIn(800);
window.location.reload();
});
//
});
//
$(function() {
        $.fn.scrollToTop = function() {
            $(this).hide().removeAttr("href");
            if ($(window).scrollTop() != "0") {
                $(this).fadeIn("slow")
            }
            var scrollDiv = $(this);
            $(window).scroll(function() {
                if ($(window).scrollTop() == "0") {
                    $(scrollDiv).fadeOut("fast");
                } else {
                    $(scrollDiv).fadeIn("slow");
                }
            });
            $(this).click(function() {
                $("html, body").animate({
                    scrollTop: 0
                }, "slow")
            })
        }
    });
    $(function() {
        $(".cp_up").scrollToTop();
    });
 </script>
</div>
<!--/CPnel-->
  <?php
    }


    function sa_validate_options($input)
    {
        global $sa_options, $sa_categories, $sa_layouts;

        $settings = get_option('sa_options', $sa_options);

        // We strip all tags from the text field, to avoid vulnerablilties like XSS
        $input['footer_copyright'] = wp_filter_nohtml_kses($input['footer_copyright']);
        $input['abdllahtxt'] = wp_filter_nohtml_kses($input['abdllahtxt']);
        $input['ali'] = wp_filter_nohtml_kses($input['ali']);

        // We strip all tags from the text field, to avoid vulnerablilties like XSS
        $input['intro_text'] = wp_filter_post_kses($input['intro_text']);

        // We select the previous value of the field, to restore it in case an invalid entry has been given
        $prev = $settings['featured_cat'];
        // We verify if the given value exists in the categories array
        if (!array_key_exists($input['featured_cat'], $sa_categories)) {
            $input['featured_cat'] = $prev;
        }

        // We select the previous value of the field, to restore it in case an invalid entry has been given
        $prev = $settings['layout_view'];
        // We verify if the given value exists in the layouts array
        if (!array_key_exists($input['layout_view'], $sa_layouts)) {
            $input['layout_view'] = $prev;
        }

        // If the checkbox has not been checked, we void it
        if (! isset($input['author_credits'])) {
            $input['author_credits'] = null;
        }
        // We verify if the input is a boolean value
        $input['author_credits'] = ($input['author_credits'] == 1 ? 1 : 0);

        return $input;
    }
}
?>
