@extends('admin.admin-master') 
@section('content')
<div>&nbsp; </div>
@if (Session::has('message'))
<span class="alert {{Session::get('class')}}">
    {{Session::get('message')}}
</span>
@endif
<div>&nbsp; </div>
<h3><i class="fa fa-bars"></i> Manage Polls  </h3>
<div>&nbsp; </div>
<div class="col-md-12">
    <div class="col-md-6">
        @if(Input::get('action')=='edit')<h3> Edit poll :</h3>@endif
        <?php $poll_img = isset($poll->image_path) ? $poll->image_path : ''; ?>
        @if($poll_img!='')
        <img src="{{$poll_img}}" id="poll_img" class="img-responsive">
        @else
        <img src="{{$poll_img}}" id="poll_img" class="img-responsive hide">
        @endif
        <!-- Form Name -->

        <?php
        $form_action = (Input::get('action') == 'edit') ? '/admin/update-poll' : '/admin/save-poll';
        $form_id = (Input::get('action') == 'edit') ? 'update_poll_form' : 'add_poll_form';
        ?>
        {{Form::open(array('url'=>$form_action,
                    'class'=>'form-horizontal',
                    'method'=>'POST',
                    'id' =>$form_id

                    ))}}

        {{Form::hidden('image_name',$poll_img,array('id'=>'file_name'))}}
        {{Form::hidden('poll_id',Input::get('poll_id'),array('id'=>'file_name'))}}
        <div class="control-group">
            <label class="control-label" for="textinput"> Poll :</label>
            <div class="controls">
                <?php $poll_id = isset($poll->poll_text) ? $poll->poll_text : ''; ?>
                {{Form::text('poll_text',$poll_id,array('id'=>'poll_text','class'=>'form-control input-sm','placeholder'=>'Poll text'))}}
            </div>
        </div>
        <div class="clearfix">&nbsp;</div>
        <div class="row">
            <div class="col-lg-6">
                <div class="input-group date form_datetime" data-date="{{date('Y-m-d H:i:s')}}" data-date-format="dd MM yyyy - HH:ii p" data-link-field="dtp_input1">
                    <?php $voting_last_date = isset($poll->voting_last_date) ? $poll->voting_last_date : ''; ?>
                    <input class="form-control input-sm" value="{{$voting_last_date}}" size="16" name="voting_last_date" type="text" readonly="" placeholder="Voting last date">
                    <span class="input-group-addon input-sm"><span class="glyphicon glyphicon-calendar"></span></span>
                </div>
                <input type="hidden" id="dtp_input1" name="voting_last_date" value="{{$voting_last_date}}">
            </div>
            <div class="col-lg-3"> <a data-toggle="tooltip" data-placement="bottom" title="Add image" class="btn btn-sm btn-info" href="javascript:void(0)" id="load-meadia"> <i class="fa fa-image"></i> </a></div>
            <div class="visible-sm visible-md">&nbsp; &nbsp;</div>
            <div class="col-lg-3">
                <div class="control-group">
                    <div class="controls">
                        {{Form::button('<i class="fa fa-edit"></i> Add Option',array('class'=>'btn btn-warning btn-sm btn-block','id'=>'add_poll_opt','type'=>'button'))}}
                    </div>
                </div>
            </div>
        </div>
        <div class="clearfix optn-rmv">&nbsp;</div>
        @if(empty($poll_options))
        <div class="input-group optn-rmv">
            {{Form::text('option_text[]','',array('class'=>'form-control input-sm opt','placeholder'=>'Poll Option'))}}
            <span class="input-group-addon btn">
                <i class="fa fa-times"></i>
            </span>
        </div><!-- /input-group -->
        <div class="clearfix optn-rmv">&nbsp;</div>
        <div class="input-group optn-rmv">
            {{Form::text('option_text[]','',array('class'=>'form-control input-sm opt','placeholder'=>'Poll Option'))}}
            <span class="input-group-addon btn" onclick="removeOpt($(this))">
                <i class="fa fa-times"></i>
            </span>
        </div>
        @else
        <?php $a = 1; ?>
        @foreach($poll_options as $p)
        <div class="clearfix optn-rmv">&nbsp;</div>
        <div class="input-group optn-rmv">
            <?php $op = 'option_text['.$p->poll_option_id.']'; ?>
            {{Form::text($op,$p->poll_option_text,array('class'=>'form-control input-sm opt','placeholder'=>'Poll Option'))}}
            <span class="input-group-addon btn" onclick="removeOpt($(this))">
                <i class="fa fa-times"></i>
            </span>
        </div>
        @endforeach
        @endif
        <!-- /input-group -->
        <div class="clearfix poll-append">&nbsp;</div>
        <!-- Button -->
        <div class="control-group">
            @if(Input::get('action')!='edit')
            <label>{{Form::checkbox('is_featured')}} Featured to Home page  &nbsp; &nbsp; &nbsp;  </label>
            @endif
        </div>

        @if(Input::get('action')=='edit')
        <div class="control-group">
            <label class="control-label" for="singlebutton"></label>
            <div class="controls hidden-xs hidden-sm">
                {{Form::button('Reset',array('class'=>'btn btn-default btn-sm','type'=>'reset','id'=>'reset_poll_form'))}}
                {{Form::button('<i class="fa fa-save"></i> Update Poll',array('name'=>'update_poll','type'=>'submit','class'=>'update_poll btn btn-info btn-sm'))}}
                <span class="poll-loader"></span>
            </div>
            <div class="controls visible-sm visible-xs">
                {{Form::button('Reset',array('class'=>'btn btn-default btn-sm visible-sm visible-xs btn-block','type'=>'reset','id'=>'reset_poll_form'))}}
                <div class="clearfix">&nbsp;</div>
                {{Form::button('<i class="fa fa-save"></i> Update Poll',array('name'=>'update_poll','type'=>'submit','class'=>'update_poll btn btn-info btn-sm visible-sm visible-xs btn-block','type'=>'button' ))}}
                <span class="poll-loader"></span>
            </div>
        </div>
        @else
        <div class="control-group">
            <label class="control-label" for="singlebutton"></label>
            <div class="controls hidden-xs hidden-sm">
                {{Form::button('Reset',array('class'=>'btn btn-default btn-sm','type'=>'reset','id'=>'reset_poll_form'))}}
                {{Form::button('<i class="fa fa-save"></i> Save Poll',array('name'=>'save_poll','id'=>'save_poll','class'=>'save_poll btn btn-info btn-sm','type'=>'button' ))}}
                <span class="poll-loader"></span>
            </div>
            <div class="controls visible-sm visible-xs">
                {{Form::button('Reset',array('class'=>'btn btn-default btn-sm visible-sm visible-xs btn-block','type'=>'reset','id'=>'reset_poll_form'))}}
                <div class="clearfix">&nbsp;</div>
                {{Form::button('<i class="fa fa-save"></i> Save Poll',array('name'=>'save_poll','id'=>'save_poll','class'=>'save_poll btn btn-info btn-sm visible-sm visible-xs btn-block','type'=>'button' ))}}
                <span class="poll-loader"></span>
            </div>
        </div>
        @endif
        {{Form::close()}}
        <!--//  End form -->

    </div>

    <div class="col-md-6">
        <h3> Poll List </h3>
        <table class="table table-condensed table-responsive">
            <tr>
                <th>Poll</th>
                <th class="hidden-sm hidden-xs"> Voting Last Date</th>
                <th class="hidden-sm hidden-xs"> Featured </th>
                <th class="hidden-sm hidden-xs">Status</th>
                <th class="hidden-sm hidden-xs">Action</th>
            </tr>
            @foreach($polls as $p)
            <tr>
                <td>{{$p->poll_text}}
                    <a class="visible-sm visible-xs" data-toggle="tooltip" data-placement="bottom" title="Click to change Feature" href="/admin/change-poll-feature-status/{{$p->poll_id}},{{$p->is_featured}}">{{($p->is_featured==1)?'<span class="label label-success">Yes</span>':'<span class="label label-danger">No</span>'}}</a>
                    <a class="visible-sm visible-xs" data-toggle="tooltip" data-placement="bottom" title="Click to change status" href="/admin/change-poll-status/{{$p->poll_id}},{{$p->status}}">{{($p->status==1)?'<span class="label label-success">Active</span>':'<span class="label label-danger">Inactive</span>'}}</a>

                    <a href="/admin/manage-poll?poll_id={{$p->poll_id}}&action=edit" class="btn btn-sm btn-info visible-sm visible-xs btn-block" poll-id="{{$p->poll_id}}" data-toggle="tooltip" data-placement="bottom" title="Edit"><i class="fa fa-edit"></i></a>
                    <button class="btn btn-sm btn-danger delete-poll visible-sm visible-xs btn-block" data-toggle="tooltip" data-placement="bottom" title="Delete Poll" poll_id="{{$p->poll_id}}"><i class="fa fa-close"></i></button>
                </td>
                <td class="hidden-sm hidden-xs">{{Util::getdate($p->voting_last_date,'d M Y')}}</td>
                <td class="hidden-sm hidden-xs"><a data-toggle="tooltip" data-placement="bottom" title="Click to change Feature" href="/admin/change-poll-feature-status/{{$p->poll_id}},{{$p->is_featured}}">{{($p->is_featured==1)?'<span class="label label-success">Yes</span>':'<span class="label label-danger">No</span>'}}</a></td>
                <td class="hidden-sm hidden-xs"><a data-toggle="tooltip" data-placement="bottom" title="Click to change status" href="/admin/change-poll-status/{{$p->poll_id}},{{$p->status}}">{{($p->status==1)?'<span class="label label-success">Active</span>':'<span class="label label-danger">Inactive</span>'}}</a></td>
                <td class="hidden-sm hidden-xs" nowrap>
                    <a href="/admin/manage-poll?poll_id={{$p->poll_id}}&action=edit" class="btn btn-sm btn-info" poll-id="{{$p->poll_id}}" data-toggle="tooltip" data-placement="bottom" title="Edit"><i class="fa fa-edit"></i></a>
                    <button class="btn btn-sm btn-danger delete-poll" data-toggle="tooltip" data-placement="bottom" title="Delete Poll" poll_id="{{$p->poll_id}}"><i class="fa fa-close"></i></button>
                </td>
            </tr>
            @endforeach
        </table>
    </div>
</div>
<div class="visible-sm visible-xs">&nbsp;</div>
@stop
