<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: 			*/
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | Copyright (c) 2004-2010 ARMIA INC                                    |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts VistaCart                     |
// +----------------------------------------------------------------------+
// | Authors: Jipson<jipson.thomas@armiasystems.com>             		  |
?>
<?php echo $javascript->link('jquery.js'); ?>
<?php echo $javascript->link('hint.js'); ?>
<script>
    function clickSearch()
    {
        document.frmSearch.submit();
    }
</script>

<script>
    function validateFields()
    {
        var i=0;
        var fcs_fld=new Array();
        var errorstr = '';
        var msgstr = "Sorry, we cannot complete your request.\nKindly provide us the missing or incorrect information enclosed below.\n\n";
        if($.trim($('#CustomfieldvalueCustomfieldId').val())==0) { errorstr += "- Please Select a Customfield Name.\n"; fcs_fld[i]='CustomfieldvalueCustomfieldId'; i++; }
        if($.trim($('#CustomfieldvalueCustomValue').val())=='') { errorstr += "- Please Enter CustomField Value.\n"; fcs_fld[i]='CustomfieldvalueCustomValue'; i++; }

        if (errorstr != '')
        {
            msgstr = msgstr + errorstr;
            alert(msgstr);
            $('#'+fcs_fld[0]+'').focus();
            return false;
        }
        else
        {
            var cstmfldid=$('#CustomfieldvalueCustomfieldId').val();
            $('#hidcstmid').val(cstmfldid)
            return true;
        }
    }
</script>

<script>
    function showEdit(id)
    {
        var total_rows=<?php echo $totrows;?>;
        for(i=0;i<=total_rows;i++)
        {
            if(i==id)
            {
                $('#edit_txt'+i+'').hide(); $('#edit_lbl'+i+'').show();
                $('#edit_box'+i+'').show();
                $('#btn_lbl'+i+'').show();
            }
            else
            {
                $('#edit_txt'+i+'').show(); $('#edit_lbl'+i+'').hide(); $('#btn_lbl'+i+'').hide();
            }
        }
        return false;
    }

    function validateField(editid,index)
    {
        if($.trim($('#edit_box'+index+'').val())=='')
        {
            alert("Please enter the customfield name");
            $('#edit_box'+index+'').focus();
            return false;
        }
        else
        {
            var cstmid=$('#cstmid'+index).val();
            $('#hidcustomid').val(cstmid)
            $('#editid').val(editid);
            $('#editindex').val(index)
            return true;
        }
    }

    function hideButtons(id)
    {
        $('#edit_txt'+id+'').show(); $('#edit_lbl'+id+'').hide(); $('#btn_lbl'+id+'').hide();
        return false;
    }
</script>

<div align="center" class="subheading">
    <div align="left">Custom Fields
        <a href="#" class="tooltip" title="In this page, you can add the custom values for the product variables that has been added through the custom fields page. For example if you have added product variables such as  Size, Color, and Fabric as custom fields. The XL,XXL, Blue, Red, and Cotton, Polyester, are the custom field values" onclick="return false;">
            <?php echo $html->image('/img/hint.png', array('border' => 0, 'text-decoration' => 'none'));?>
        </a>
    </div>
</div>
<br />
<?php if($session->check('Message.flash')) { ?><div id="okbox"><font color="#446423"><?php $session->flash(); ?></font></div><?php } ?>

<!--items add area start -->
<div align="left" id="item_details_admin">
    <div align="left" class="inner_content_area_admin">
        <!--form area start -->
        <?php echo $form->create('Customfieldvalue', array('name' =>'Customfieldvalue')); ?>
        <div id="admin_heading">Add Custom Field Value </div>
        <div id="grid_admin">
            <div align="left" id="inner_leftcontent">
                <p class="maintext_inner">Custom Field Name<span class="required_field">*</span></p>
            </div>
            <div align="right" id="inner_rightcontent">
                <span class="toplinks">
                    <?php
                    $customfields[0]='---------------- Select ------------------';
                    ksort($customfields);
                    echo $form->input('customfield_id', array('options' => $customfields,'label' => '','class' => 'box2_admin')); ?>
                </span>
            </div>
            <div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif', array('width' => 1, 'height' => 1));?></div>
        </div>


        <div id="grid_admin">
            <div align="left" id="inner_leftcontent">
                <p class="maintext_inner">Custom Field Value  <span class="required_field">*</span></p>
            </div>
            <div align="right" id="inner_rightcontent">
                <span class="toplinks">
                    <?php echo $form->input('custom_value', array('label' => '','class' => 'box2_admin','size'=>27));?>
                </span>
            </div>
            <div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif', array('width' => 1, 'height' => 1));?></div>
        </div>

        <div id="admin_bottom">
            <div align="left" id="inner_leftcontent">
                <p class="maintext_inner">&nbsp;</p>
            </div>
            <div align="right" id="inner_rightcontent">
                <span class="toplinks">
                    <input name="submit" type="submit" class="buttn_admin" onclick="return validateFields();" value="Save" />
                    <input name="button" type="button" class="buttn_admin" onclick="javascript:history.go(-1);" value="Cancel" />
                </span>
            </div>
            <div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif', array('width' => 1, 'height' => 1));?></div>
            <input type="hidden" id="hidcstmid" name="hidcstmid" value=""/>
            <?php echo $form->end(); ?>
            <!--form area end -->
        </div>
    </div>
    <div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif', array('width' => 1, 'height' => 1));?></div>
    <br /> <br />
    <!-- End of Add Area -->


    <!--items search area start -->
    <form action="<?php echo $sitebase.$sitefolder.'/'.$this->params["controller"];?>" method="get" name="frmSearch">
        <div>
            <div style=float:left>
                <select name="cmbSearchType"  class="box2_admin">
                    <option value="name"  <?php if($cmbSearchType == "name" || $cmbSearchType == "") {
    echo("selected");
} ?>>Custom Field Value</option>
                </select> &nbsp;
                <input type="text" name="txtSearch" maxlength="50" value="<?php echo(htmlentities($txtSearch)); ?>"  class="box2_admin">
            </div>
            <div>
                <a style="cursor:pointer" onClick="javascript:clickSearch();"><?php echo $html->image('/img/search_bttn.gif');?></a>
            </div>
        </div>
        <br />
    </form>
    <!--items search area end -->



    <!--items display area start -->
    <div align="center" id="items_display_area_admin">
        <form name="customlist" method="post" action="<?php echo $this->params['controller'];?>/edit">
            <div id="list_admin_top">
                <div class="list9"><strong>#</strong></div>
                <div class="list5"><strong><?php echo $paginator->sort('Custom Field value', 'Customfieldvalue.custom_value'); ?></strong></div>
                <div class="list7"><strong><?php echo $paginator->sort('Custom Field', 'Customfield.custom_name'); ?></strong></div>
                <div class="list6"><strong>Edit/Delete</strong></div>
                <div align="left" class="float_clear"><?php echo $html->image('/img/clear.gif', array('width' => 1, 'height' => 1));?></div>
            </div>

            <?php
            $i=0;
            $j=0;
            if(!empty($passedarg) && !isset($passedarg["page"]))
                $cnt=1;
            else if(!empty($passedarg) && $passedarg["page"]==1)
                $cnt=1;
            else
                $cnt=((($passedarg["page"]-1)*($passedarg["limit"]))+1);
if(!empty($customfieldvalue)) {
    foreach ($customfieldvalue as $fieldvalue) {?>
            <div id="list_admin">
                <div class="list9"><?php echo $cnt++;?></div>
                <div class="list5">
                    <label id="edit_txt<?php echo $j;?>">
        <?php echo Sanitize::html($fieldvalue['Customfieldvalue']['custom_value']); ?>
                    </label>
                    <label id="edit_lbl<?php echo $j;?>" style="display:none;">
                        <input type="text" id="edit_box<?php echo $j;?>"  name="edit_cname<?php echo $j;?>"
                               value="<?php echo $fieldvalue['Customfieldvalue']['custom_value'];?>" />
                    </label>
                    <label id="btn_lbl<?php echo $j;?>" style="display:none;">
                        <input type="submit" value="Update" onClick="return validateField('<?php echo $fieldvalue['Customfieldvalue']['id'];?>','<?php echo $j;?>');">
                        <input type="button" value="Cancel" onClick="return hideButtons('<?php echo $j;?>');">
                    </label>

                    <input type="hidden" id="cstmid<?php echo $j;?>"  name="cstmid<?php echo $j;?>" value="<?php echo $fieldvalue['Customfieldvalue']['customfield_id'];?>" />
                </div>
                <div class="list7">
        <?php echo Sanitize::html($fieldvalue['Customfield']['custom_name']); ?>
                </div>

                <div class="list6">
        <?php echo $html->link("Edit","/customfieldvalues/edit/",array("onclick"=>"return showEdit($i)")) ." / ".  $html->link('Delete',"/customfieldvalues/delete/".$fieldvalue['Customfieldvalue']['id'],null,'Are you sure you want to delete this Custom Field Value'); ?>
                </div>


                <div align="left" class="float_clear"><?php echo $html->image('/img/clear.gif', array('width' => 1, 'height' => 1));?></div>
            </div>
                    <?php
        $i++;
        $j++;
                        } ?>
            <div id="admin_bottom">
                <div>
                        <?php
                        if($cmbSearchType <> '' &&  $txtSearch <> '') {
        $paginator->options(array('url'=>array_merge(array('cmbSearchType'=>$cmbSearchType,
                'txtSearch'=>$txtSearch),$this->passedArgs)));
    }  ?>
                <?php echo $paginator->numbers(); ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $paginator->counter(); ?>
                </div>
                <div align="left" class="float_clear"><?php echo $html->image('/img/clear.gif', array('width' => 1, 'height' => 1));?></div>
            </div>
    <? } else { ?>
            <div id="list_admin">
                <div>&nbsp;</div>
                <div><strong>Sorry no Custom Field values found!</strong></div>
                <div align="left" class="float_clear"><?php echo $html->image('/img/clear.gif', array('width' => 1, 'height' => 1));?></div>
            </div>
    <?php } ?>
            <input type="hidden" id="editid" name="editid" value=""/>
            <input type="hidden" id="editindex" name="editindex" value=""/>
            <input type="hidden" id="hidcustomid" name="hidcustomid" value=""/>
        </form>
        <!--items display area end -->

    </div>
    <div align="left" class="float_clear1"></div>
</div>
<div align="left" class="float_clear1"><?php echo $html->image('/img/clear.gif');?></div>