<style type="text/css">
    .grey{
        color:#AEAEAE;
    }
    .green{
        color:#5CA45C;
    }
    .messageBox {
        background-color: #EAEAEA;
        border: 1px solid #C9C9C9;
        padding: 25px 15px;
        width: 850px;
        margin-bottom: 10px;
    }   
</style>
<script type="text/javascript">

    function loadSubCategories(catId){
        //alert(catId);return false;
        if(catId!=''){
            $.ajax({

            type: "POST",
            url: "<?php echo ConfigUrl::base('admin');?>index/loadSubCategories",
            data: {
                categoryId: catId
            },
            success: function(html) {
                //alert(html);
                $('#sub').html(html);
            }


        });
        }
    }
 </script>
<div class="inner_rightpanel">
    <div class="comm_content_block"> <h3>Edit Listing</h3></div>
    <?php
    if(!empty($this->error) || !empty($this->message)) {
        $messageClass = (!empty($this->error)) ? 'red' : 'green';
        $flashMessage = (!empty($this->error)) ? $this->error : $this->message;
        ?>
    <div><span class="<?php echo $messageClass ?>"><?php echo $flashMessage; ?></span></div>
        <?php
    } //
    // echo "<pre>";print_r($this->fieldValuesArr[0]);
    ?>

    <div class="postad_div">
        <form method="post" name="frmPostads" id="frmPostads" action="<?php echo ConfigUrl::base(); ?>index/edit" enctype="multipart/form-data">
            <input type="hidden" name="BusId" value="<?php echo $this->fieldValuesArr[0]->nBusId ?>">
            <table width="100%"  class="form_tbls" border="0" cellspacing="0" cellpadding="0">
                <?php
                if(!empty($this->activeFields)) {
                    //Title Field
                    if(strtolower($this->activeFields[0]->vFldname)==strtolower('Title')) {
                        $fieldName = $this->activeFields[0]->vFldname;
                        ?>
                <tr>
                    <td width="33%"><p><?php echo $this->activeFields[0]->vFlddesc ?><?php if($this->activeFields[0]->nMandatory==1) { ?><font color="red">*</font><?php } ?></p></td>
                    <td width="3%">:</td>
                    <td width="64%"><input type="text" class="txt_area form-tbl-txt" name="<?php echo $this->activeFields[0]->vFldname ?>" value="<?php echo stripslashes($this->fieldValuesArr[0]->$fieldName); ?>"></td>
                </tr>
                        <?php
                    } //Title Field End

                    ?>
                <tr>
                <td><p>Select Category</p></td>
                <td>:</td>
                <td>
                    <!--<select class="select_drpbx" name="select">
                        <option>Category</option>
                    </select>-->
                    <?php
                    if(!empty($this->category_title)) { asort($this->category_title); }
                    ?>
                    <?php echo $this->select('category', $this->category_title,$this->parentCategory, 'select_drpbx','','category',' size="10" onChange = loadSubCategories(this.value)'); ?>
                </td>
            </tr>
            <tr >
                    <td><p>Select Subcategory</p></td>
                    <td>:</td>
                    <td id ="sub">
                        <?php
                        if($this->parentCategory>0){
                          echo $this->select('subcategory', $this->subCategoryList,$this->SubCategory, 'select_drpbx','','subcategory',' size="4"');
                        }else{
                           echo $this->select('subcategory','', $this->fieldValuesArr[0]->nCatid, 'select_drpbx','','subcategory',' size="4"');
                        }
                          ?>
                    </td>
                </tr>
                    <?php
                    foreach($this->activeFields as $activeFld) {
                        $fieldName = '';
                        $fieldName = $activeFld->vFldname;
                        if(in_array($activeFld->vFldname, $this->staticFieldArr)) {

                            switch(strtolower($activeFld->vFldname)) {
                                case 'title':
                                    break;
                                case 'description':

                                    ?>
                <tr>
                    <td valign="top"><p><?php echo $activeFld->vFlddesc ?><?php if($activeFld->nMandatory==1) { ?><font color="red">*</font><?php } ?></p></td>
                    <td>&nbsp;</td>
                    <td><textarea class="txtarea form-tbl-txta" name="<?php echo $activeFld->vFldname; ?>"><?php echo stripslashes($this->fieldValuesArr[0]->$fieldName); ?></textarea></td>
                </tr>
                                    <?php
                                    break;
                                case 'image':
                                    ?>
                <tr>
                    <td width="33%" class="form0tbl-mgn"><p><?php echo $activeFld->vFlddesc ?><?php if($activeFld->nMandatory==1) { ?><font color="red">*</font><?php } ?></p></td>
                    <td width="3%" class="form0tbl-mgn">:</td>
                    <td width="64%" class="form0tbl-mgn"><input type="file" class="txt_area form-tbl-txt" name="<?php echo $activeFld->vFldname; ?>">
                                            <?php
                                            if(!empty($this->fieldValuesArr[0]->$fieldName)) {
                                                $imageName = $this->fieldValuesArr[0]->$fieldName;
                                                $imageParts=pathinfo($imageName);
                                                $imageNameArr = explode("_302x302", $imageName);
                                                $imageNameThumb = $imageNameArr[0].'_151x151.'.$imageParts['extension'];
                                                $postImage=ConfigUrl::uploadimageroot().$imageNameThumb;
                                                if(is_file($postImage)) {
                                                    ?>
                        <img src="<?php echo ConfigUrl::base('default').'uploads/image/'.$imageNameThumb; ?>" alt="Image" /><br>
                                                    <?php
                                                } // Thumb View
                                            } // Image Field Value Exists
                                            ?>
                        <br><span class="grey">Allowed image type : jpg/jpeg</span></td>
                </tr>
                                    <?php
                                    break;
                                case 'video':
                                    ?>
                <tr>
                    <td width="33%"><p><?php echo $activeFld->vFlddesc ?><?php if($activeFld->nMandatory==1) { ?><font color="red">*</font><?php } ?></p></td>
                    <td width="3%">:</td>
                    <td width="64%"><input type="file" class="txt_area form-tbl-txt" name="<?php echo $activeFld->vFldname; ?>">
                                            <?php
                                            if(!empty($this->fieldValuesArr[0]->$fieldName)) {
                                                $fileName = $this->fieldValuesArr[0]->$fieldName;
                                                $fileParts=pathinfo($fileName);
                                                $imageNameThumb = $imageParts['filename'].'.jpeg';
                                                $postFile = ConfigUrl::uploadvideoroot().$imageNameThumb;
                                                if(is_file($postFile)) {
                                                    ?>
                        <img src="<?php echo ConfigUrl::base('default').'uploads/video/'.$imageNameThumb; ?>" alt="Image" /><br>
                                                    <?php
                                                } // Thumb View
                                            } // Image Field Value Exists
                                            ?>
                        <br><span class="grey">Supported video formats : mp4,webm,ogv,flv
                            <br>Maximum File Upload Size allowed by your server - <?php echo ini_get('upload_max_filesize'); ?>
                        </span>
                        <?php if(trim($this->fieldValuesArr[0]->$fieldName) <> ""){ ?>
                        <br/><br/>
                        <a href="<?php echo ConfigUrl::root().'uploads/video/'.stripslashes($this->fieldValuesArr[0]->$fieldName); ?>" target="_blank" style="color:#F00;">Download Video Now</a>
                        <?php } ?>
                    </td>
                </tr>
                                    <?php
                                    break;
                                case 'videourl':
                                    ?>
                <tr>
                    <td width="33%"><p><?php echo $activeFld->vFlddesc ?><?php if($activeFld->nMandatory==1) { ?><font color="red">*</font><?php } ?></p></td>
                    <td width="3%">:</td>
                    <td width="64%"><input type="text" class="txt_area form-tbl-txt" name="<?php echo $activeFld->vFldname; ?>" value="<?php echo $this->fieldValuesArr[0]->$fieldName; ?>"></td>
                </tr>
                                    <?php
                                    break;
                                case 'zipcode':
                                    ?>
                <tr>
                    <td width="33%"><p><?php echo $activeFld->vFlddesc ?><?php if($activeFld->nMandatory==1) { ?><font color="red">*</font><?php } ?></p></td>
                    <td width="3%">:</td>
                    <td width="64%"><input type="text" class="txt_area form-tbl-txt" name="<?php echo $activeFld->vFldname; ?>" value="<?php echo stripslashes($this->fieldValuesArr[0]->$fieldName); ?>"></td>
                </tr>
                                    <?php
                                    break;
                                case 'address':
                                    ?>
                <tr>
                    <td valign="top"><p><?php echo $activeFld->vFlddesc ?><?php if($activeFld->nMandatory==1) { ?><font color="red">*</font><?php } ?></p></td>
                    <td>&nbsp;</td>
                    <td><textarea class="txtarea  form-tbl-txta" name="<?php echo $activeFld->vFldname; ?>"><?php echo stripslashes($this->fieldValuesArr[0]->$fieldName); ?></textarea></td>
                </tr>
                                    <?php
                                    break;
                            } //End Switch

                        } // End If

                        if(!in_array($activeFld->vFldname, $this->staticFieldArr)) {
                            switch(($activeFld->vInType)) {
                                case 'text':
                                    ?>
                <tr>
                    <td width="33%"><p><?php echo $activeFld->vFlddesc ?><?php if($activeFld->nMandatory==1) { ?><font color="red">*</font><?php } ?></p></td>
                    <td width="3%">:</td>
                    <td width="64%"><input type="text" class="txt_area form-tbl-txt" name="<?php echo $activeFld->vFldname; ?>" value="<?php echo stripslashes($this->fieldValuesArr[0]->$fieldName); ?>"></td>
                </tr>
                                    <?php
                                    break;

                                case 'textarea':
                                    ?>
                <tr>
                    <td valign="top"><p><?php echo $activeFld->vFlddesc ?><?php if($activeFld->nMandatory==1) { ?><font color="red">*</font><?php } ?></p></td>
                    <td>&nbsp;</td>
                    <td><textarea class="txtarea form-tbl-txta" name="<?php echo $activeFld->vFldname; ?>"><?php echo stripslashes($this->fieldValuesArr[0]->$fieldName); ?></textarea></td>
                </tr>
                                    <?php
                                    break;
                                case 'file-doc/txt':
                                    ?>
                <tr>
                    <td width="33%"><p><?php echo $activeFld->vFlddesc ?><?php if($activeFld->nMandatory==1) { ?><font color="red">*</font><?php } ?></p></td>
                    <td width="3%">:</td>
                    <td width="64%"><input type="file" class="txt_area form-tbl-txt" name="<?php echo $activeFld->vFldname; ?>">
                                            <?php
                                            if(!empty($this->fieldValuesArr[0]->$fieldName)) {
                                                $fileName = $this->fieldValuesArr[0]->$fieldName;
                                                $postFile = ConfigUrl::uploaddocroot().$fileName;
                                                if(is_file($postFile)) {

                                                    ?>
                        <a href="<?php echo ConfigUrl::base() ?>ads/downloaddoc/<?php echo $fileName ?>"></a><br>
                                                    <?php
                                                } // Download Files
                                            } // Image Field Value Exists
                                            ?>
                        <br><span class="grey">Supported file formats : doc,pdf,xls</span>
                    </td>
                </tr>
                                    <?php
                                    break;
                                case 'checkbox':
                                    ?>
                <tr>
                    <td width="33%"><p><?php echo $activeFld->vFlddesc ?><?php if($activeFld->nMandatory==1) { ?><font color="red">*</font><?php } ?></p></td>
                    <td width="3%">:</td>
                    <td width="64%"><?php echo $this->checkbox($activeFld->vFldname, '1', $this->fieldValuesArr[0]->$fieldName, 'chkbx_manage',$activeFld->vFldname); ?></td>
                </tr>
                                    <?php
                                    break;

                            } // End Switch
                        } // End If

                    } //
                } // End If
                ?>
                <tr>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>
                        <div class="postad_btn">
                            <input name="" class="btn_styles" value="POST AD" type="submit">
                        </div>
                    </td>
                </tr>
            </table>
        </form>

        <div class="clear"></div>
    </div>

    <div class="clear"></div>
</div>


<div class="clear"></div>
</div>
<!-- Inner Content Wrap End -->
<div class="clear"></div>
</div>
