<?php 

@include "includes/header.php";



if (isset($_GET['action']) && ($_GET['action'] == "addnew" || $_GET['action'] == "edit")) {



    if ($_GET['action'] == "edit") {

        $info_array = array(

            "primarykey" => "id",

            "where" => "id='" . $_GET['id'] . "'",

            "limit" => "1",

        );

        $datarecords = $Main->GetRecord("lts_parameters", $info_array);

        $data = $datarecords[$_GET['id']];
        $info_array_label = array(

            "primarykey" => "id",

            "where" => "english_identifier LIKE '" .$data['parameter_name']. "'",

            "limit" => "1",

        );
        $datarecords_label = $Main->GetRecord("lts_label_managment", $info_array_label);
        foreach ($datarecords_label as $key2 => $value2) {
            $data_label_id['1']= $value2;
        }
        $data_label = $data_label_id['1'];
        $disable="disabled";

    }

    ?>

    <div class="row">

        <div class="col-md-12">

            <br>

            <div id="myTabContent" class="tab-content">

                <div class="tab-pane active in" id="home">

                    <form method="post" id="parameter_form" enctype="multipart/form-data">

                        <div class="form-group">

                            <lable>

                                <?php $Main->LanguageString("Parameter"); ?>
                                <span class="text-danger error-size">*</span>

                            </lable>

                            <input type="text" name="parameter_name" id="parameter_name" class="validate[required] form-control" value="<?php echo stripslashes(@$data['parameter_name']); ?>">

                        <?php if(isset($disable)){?>
                            <input type="hidden" name="label_id" value="<?php echo  @$data_label['id'] ?>">
                            <?php } ?>
                        </div>
                        <?php
                            $language_list = array(

                                "primarykey" => "id",

                                "fields" => "*",

                                "where" => "active_status='1'",

                                "orderby" => "id",

                                "ordertype" => "asc",

                            );

                            $language_array = $Main->GetRecord("lts_language", $language_list);
                            foreach ($language_array as $key1 => $value1) { ?>
                            <div class="form-group">

                            <lable>

                                <?php $Main->LanguageString("Parameter");
                                      echo " ".ucfirst($value1['language_title'])." ";
                                      echo "title";
                                 ?>
                                <span class="text-danger error-size">*</span>

                            </lable>

                            <input type="text" name="<?php echo @$value1['identifier']?>" id="<?php echo @$value1['identifier']?>" class="validate[required] form-control" value="<?php echo @$data_label[$value1['identifier']]; ?>">

                        </div>
                            <?php } ?>

                        <div class="form-group">

                            <lable>

                                <?php $Main->LanguageString("Natureofbusiness"); ?>
                             <span class="text-danger error-size">*</span>

                            </lable>

                            <select name="nature_of_business" id="nature_of_business" class="validate[required] form-control">

                                <option value=""><?php $Main->LanguageString("Select"); ?></option>

                                <?php

                                $query = mysql_query("SELECT id,title FROM lts_nature_of_business WHERE active_status=1");

                                while ($fetchdata = mysql_fetch_assoc($query)) {

                                    ?>

                                    <option value="<?php echo stripslashes(@$fetchdata['id']); ?>" <?php if (@$data['nature_of_business'] == @$fetchdata['id']) {

                                echo "selected";

                            } ?>>

                                    <?php $Main->LanguageString(@$fetchdata['title']); ?>

                                    </option>

    <?php } ?>

                            </select>

                        </div>

                        <div class="form-group">

                            <lable>

    <?php $Main->LanguageString("Activestatus"); ?>

                            </lable>

                            <select name="active_status" id="active_status" class="form-control">

                                <option value="1" <?php if (@$data['active_status'] == "1") {

        echo "selected";

    } ?>><?php $Main->LanguageString("Active"); ?></option>

                                <option value="0" <?php if (@$data['active_status'] == "0") {

        echo "selected";

    } ?>><?php $Main->LanguageString("Inactive"); ?></option>

                            </select>

                        </div>

                        <div class="btn-toolbar list-toolbar">

                            <input type="submit" name="manageparameters_<?php echo $_GET['action']; ?>" value="<?php $Main->LanguageString("Save"); ?>" class="btn btn-primary">

                            <input type="button" name="cancel_button" value="<?php $Main->LanguageString("Cancel"); ?>" onclick="window.location = 'manageparameters.php';" class="btn btn-success">

                        </div>

                    </form>

                </div>

            </div>

        </div>

    </div>

<?php } else {

    ?>

    <div class="btn-toolbar list-toolbar">

        <div class="btn-group"></div>

    </div>

    <div class="row col-lg-12">

        <a href="manageparameters.php?action=addnew" style="float: left;">

            <button class="btn btn-primary"><i class="fa fa-plus"></i>

                        <?php $Main->LanguageString("Addnew"); ?>

            </button>

        </a>

        <table class="table table-bordered table-striped sortable" id="datatable">

            <thead>

                <tr>

                    <th style="width:75px">

                        <?php $Main->LanguageString("Srno"); ?>

                    </th>

                    <th>

                        <?php $Main->LanguageString("Parameter"); ?>

                    </th>

                    <th>

    <?php $Main->LanguageString("Natureofbusiness"); ?>

                    </th>

                    <th style="width:25%">

                <?php $Main->LanguageString("Action"); ?>

                    </th>

                </tr>

            </thead>

            <tbody>

                <?php

                $startfrom = 0;

                $limit = $_SESSION['pagerecords_limit'];



                if (isset($_GET['page']) && is_numeric($_GET['page'])) {

                    $startfrom = ($_GET['page'] * $_SESSION['pagerecords_limit'] - $_SESSION['pagerecords_limit']);

                }



                $info_array = array(

                    "primarykey" => "id",

                    "fields" => "*",

                    "orderby" => "id",

                    "ordertype" => "asc"

                );

                $records = $Main->GetRecord("lts_parameters", $info_array);



                //if (@count($records) > 0) {

                    $i = $startfrom;

                    foreach ($records as $key => $value) {

                        $i++;

                        ?>

                        <tr>

                            <td>

                            <?php /* echo stripslashes($value['user_id']) */;

                            echo $i;

                            ?>

                            </td>

                            <td>

                                <?php echo stripslashes($value['parameter_name']); ?>

                            </td>

            <?php

            $query = mysql_query("SELECT id,title FROM lts_nature_of_business where id=" . $value['nature_of_business']);

            $fetchdata = mysql_fetch_assoc($query);

            ?>

                            <td>

                                <?php echo stripslashes(@$fetchdata['title']); ?>

                            </td>

                            <td>

                                <a href="manageparameters.php?do=parameters&action=edit&id=<?php echo $key; ?>" class="label label-info" style="margin-right:4px;">

                                    <i class="fa fa-edit"></i>

                                <?php $Main->LanguageString("Edit"); ?>

                                </a>

                                    <?php if ($value['active_status'] == 0) { ?>

                                    <a href="manageparameters.php?do=parameters&action=status&status=1&id=<?php echo $key; ?>" onclick="return confirm('Are You Sure To Activate This Record');"><span  class="label label-default"><?php $Main->LanguageString("Inactive"); ?></span></a>

            <?php } else { ?>

                                    <a href="manageparameters.php?do=parameters&action=status&status=0&id=<?php echo $key; ?>" onclick="return confirm('Are You Sure To Deactivate This Record');"><span  class="label label-success"><?php $Main->LanguageString("Active"); ?></span></a>

                        <?php }

                        ?>

                                <a href="manageparameters.php?do=parameters&action=delete&id=<?php echo $key; ?>" class="label label-danger" onclick="return confirm('Are You Sure To Delete This Record?');" style="margin-right:4px;">

                                    <i class="fa fa-times"></i>

                        <?php $Main->LanguageString("Delete"); ?>

                                </a>

                            </td>

                        </tr>

            <?php

        }

    //}

    ?>

            </tbody>

        </table>

    </div>

    <div class="row"></div>

    <?php

}

?>

<?php @include "includes/footer.php"; ?>