<form action="<?php echo $input->form_action?>" method="get" name="SearchFormRight">
	<input type="hidden" name="doSearch" value="1">
	<div class="row">		
		<div class="col-md-6">
		    <div class="form-group">
    			<label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Date range from to');?></label>
    			<div class="row">
    				<div class="col-md-6">
    					<input type="text" class="form-control form-control-sm" name="timefrom" id="id_timefrom" placeholder="E.g <?php echo date('Y-m-d',time()-7*24*3600)?>" value="<?php echo htmlspecialchars($input->timefrom)?>" />
    				</div>
    				<div class="col-md-6">
    					<input type="text" class="form-control form-control-sm" name="timeto" id="id_timeto" placeholder="E.g <?php echo date('Y-m-d')?>" value="<?php echo htmlspecialchars($input->timeto)?>" />
    				</div>
    			</div>
			</div>
		</div>
        <div class="col-md-3">
            <div class="form-group">
                <label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Department');?></label>
                <?php echo erLhcoreClassRenderHelper::renderMultiDropdown( array (
                    'input_name'     => 'department_ids[]',
                    'optional_field' => erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Choose department'),
                    'selected_id'    => $input->department_ids,
                    'css_class'      => 'form-control',
                    'display_name'   => 'name',
                    'ajax'           => 'deps',
                    'list_function_params' => array_merge(['sort' => '`name` ASC','limit' => 50],erLhcoreClassUserDep::conditionalDepartmentFilter()),
                    'list_function'  => 'erLhcoreClassModelDepartament::getList'
                )); ?>
            </div>
        </div>
        <div class="col-md-3">
            <div class="form-group">
                <label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Department group');?></label>
                <?php echo erLhcoreClassRenderHelper::renderMultiDropdown( array (
                    'input_name'     => 'department_group_ids[]',
                    'optional_field' => erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Choose department group'),
                    'selected_id'    => $input->department_group_ids,
                    'css_class'      => 'form-control',
                    'display_name'   => 'name',
                    'list_function_params' => array_merge(['sort' => '`name` ASC'],erLhcoreClassUserDep::conditionalDepartmentGroupFilter()),
                    'list_function'  => 'erLhcoreClassModelDepartamentGroup::getList'
                )); ?>
            </div>
        </div>
	</div>
	<div class="row">
        <?php include(erLhcoreClassDesign::designtpl('lhchat/lists/parts/user_title.tpl.php')); ?>
        <div class="col-md-3">
            <div class="form-group">
                <label><?php echo $userTitle['user'];?></label>
                <?php echo erLhcoreClassRenderHelper::renderMultiDropdown( array (
                    'input_name'     => 'user_ids[]',
                    'optional_field' => $userTitle['user_select'],
                    'selected_id'    => $input->user_ids,
                    'css_class'      => 'form-control',
                    'display_name'   => 'name_official',
                    'ajax'           => 'users',
                    'list_function_params' => array_merge(erLhcoreClassGroupUser::getConditionalUserFilter(),array('sort' => '`name` ASC', 'limit' => 50)),
                    'list_function'  => 'erLhcoreClassModelUser::getUserList',
                )); ?>
            </div>
        </div>
        <?php include(erLhcoreClassDesign::designtpl('lhchat/lists/parts/user_group_title.tpl.php')); ?>
        <div class="col-md-3">
            <div class="form-group">
                <label><?php echo $userGroupTitle['user_group'];?></label>
                <?php echo erLhcoreClassRenderHelper::renderMultiDropdown( array (
                    'input_name'     => 'group_ids[]',
                    'optional_field' => $userGroupTitle['user_group_select'],
                    'selected_id'    => $input->group_ids,
                    'css_class'      => 'form-control',
                    'display_name'   => 'name',
                    'list_function_params' => array_merge(array('sort' => '`name` ASC'),erLhcoreClassGroupUser::getConditionalUserFilter(false, true)),
                    'list_function'  => 'erLhcoreClassModelGroup::getList'
                )); ?>
            </div>
        </div>

	</div>
	<?php include(erLhcoreClassDesign::designtpl('lhsurvey/forms/fields_names.tpl.php'));?>
	
	<div class="row">
	<?php for ($i = 0; $i < 16; $i++) : ?>    
    	<?php foreach ($sortOptions as $keyOption => $sortOption) : ?>    	   		    
    		<?php if ($survey->{$keyOption . '_pos'} == $i && $survey->{$keyOption . '_enabled'} == 1) : ?>
    			<?php if ($sortOption['type'] == 'stars') : ?>
    			<div class="col-3">
    				<div class="form-group">
				    	<label><?php echo htmlspecialchars($survey->{$sortOption['field'] . '_title'});?></label>
				    	<select name="<?php echo $sortOption['field']?>[]" class="form-control form-control-sm" multiple="multiple" size="5">
				    		<option value="0"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Any')?></option>
				        <?php for ($n = 1; $n <= $survey->{$sortOption['field']}; $n++) : ?>
				        	<option value="<?php echo $n?>" <?php if (is_array($input->{$sortOption['field']}) && in_array($n, $input->{$sortOption['field']})) : ?>selected="selected"<?php endif;?>><?php echo $n?> stars</option>
				        <?php endfor;?>      
				        </select>
				    </div>
				</div>
    			<?php endif;?>
    			
    			<?php if ($sortOption['type'] == 'question_options') : ?>
    			<div class="col-3">
    				<div class="form-group">
				    	<label><?php echo htmlspecialchars($survey->{$sortOption['field']});?></label>				    	
				    	<select name="<?php echo $sortOption['field']?>" class="form-control form-control-sm">
				    		<option value="0"><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Any')?></option>
				        	<?php foreach ($survey->{$sortOption['field'] . '_items_front'} as $key => $item) : ?>
				        		<option value="<?php echo $key+1?>" <?php if ($input->{$sortOption['field']} == ($key+1)) : ?>selected="selected"<?php endif;?>><?php echo erLhcoreClassSurveyValidator::parseAnswerPlain($item['option'])?></option>
				        	<?php endforeach;?>      
				        </select>				        
				    </div>
				</div>
    			<?php endif;?>
    			
			<?php endif;?>
		<?php endforeach;?>
	<?php endfor;?>
	</div>
	
	
	<div class="row">
	   <div class="col-3">
	       <label><input ng-model="group_results" ng-init="group_results = <?php ($input->group_results == true) ? print 'true' : 'false' ?>" type="checkbox" name="group_results" value="on" <?php if ($input->group_results == true) : ?>checked="checked"<?php endif;?>/> <?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Group results by operator');?></label>
	   </div>
	   <div class="col-3">
    	   <div class="form-group" ng-show="group_results">
    	      <label><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Minimum operator chats');?></label>
    	      <input class="form-control form-control-sm" type="text" name="minimum_chats" placeholder="<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Optional')?>" value="<?php echo htmlspecialchars((string)$input->minimum_chats)?>" />
    	   </div>
	   </div>
	</div>
	<div class="btn-group mb-2" role="group" aria-label="...">
		<input type="submit"  name="doSearch" class="btn btn-secondary" value="<?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Search');?>" />
		
		<?php if ($pages->items_total > 0) : ?>
		<a target="_blank" class="btn btn-secondary" href="<?php echo $pages->serverURL?>/(print)/1"><i class="material-icons">print</i><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','Print');?></a>

		<?php if ($input->group_results == true) : ?>
            <a target="_blank" class="btn btn-secondary" href="<?php echo $pages->serverURL?>/(xls)/1"><i class="material-icons">&#xE2C4;</i><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','XLS');?></a>
        <?php else : ?>
            <a target="_blank" class="btn btn-secondary" href="<?php echo $pages->serverURL?>/(csvlist)/1"><i class="material-icons">&#xE2C4;</i><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','CSV');?></a>
            
            <a target="_blank" class="btn btn-secondary" href="<?php echo $pages->serverURL?>/(xlslist)/1"><i class="material-icons">&#xE2C4;</i><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','XLS');?></a>

            <a target="_blank" class="btn btn-secondary" href="<?php echo $pages->serverURL?>/(xml)/1"><i class="material-icons">&#xE2C4;</i><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','XML');?></a>

            <a target="_blank" class="btn btn-secondary" href="<?php echo $pages->serverURL?>/(json)/1"><i class="material-icons">&#xE2C4;</i><?php echo erTranslationClassLhTranslation::getInstance()->getTranslation('chat/lists/search_panel','JSON');?></a>
        <?php endif;?>
		
		<?php endif; ?>
	</div>	
</form>

<script>
$(function() {

	$('#id_timefrom,#id_timeto').fdatepicker({
		format: 'yyyy-mm-dd'
	});

    $('.btn-block-department').makeDropdown();
});
</script>