<!-- Main content -->
<div class="content-wrapper">
    <!-- Dashboard content -->
    <div class="row">
        <div class="col-lg-6">
            <!-- Daily sales -->
            <div class="panel panel-flat">
                <div class="panel-heading">
                    <div class="text-right">
                        <button type="button" class="btn btn-info btn-xs" onclick="addtranslator()">Add New Translator</button>          
                    </div>
                </div>

                <div class="table-responsive">
                    <table class="table text-nowrap">
                        <thead>
                            <tr>
                                <th>My Translators</th>     
                                <th></th>
                            </tr>
                        </thead>
                        <tbody>

                            <?
                            foreach ($result_list as $rect) {
                                ?>
                                <tr>
                                    <td>
                                        <div class="media-body"> </div>
                                        <div class="heading">
                                            <b><?= $rect['firstname'] ?> <?= $rect['lastname'] ?></b>,<br> <?= $rect['street'] ?>,<br><?= $rect['city'] ?>,<?= $rect['state'] ?> <?= $rect['zipcode'] ?>
                                        </div>



                                    </td>   
                                    <td style="width:190px;">   
                                        <div class="btn-group btn-group-xs" role="group">
                                            <button type="button" class="btn btn-info" onclick="edittranslator(<?= $rect['id'] ?>,<?= $rect['agent_id'] ?>);">Edit</button>
                                            <button type="button" class="btn btn-primary" id="accs<?= $rect['id'] ?>" onclick="manageLanguage(<?= $rect['id'] ?>,<?= $rect['agent_id'] ?>);">languages</button>
                                        </div>             
                                    </td>
                                </tr>  
                                <?
                            }
                            ?>
                        </tbody>
                    </table>
                </div>

            </div>
            <!-- /daily sales -->

        </div>

        <div class="col-lg-6">
            <!-- Daily sales -->
            <div class="panel panel-flat">
                <div class="panel-heading">
                    <h6 class="panel-title">Manage Translators</h6>
                    <div class="heading-elements">

                    </div>
                </div>

                <div class="panel-body">
                    <div id="action_panel_translator" style="display:none;"></div>
                    <div id="action_panel">
                        <?= $message ?>
                        <form class="form-horizontal form-validate-jquery" method="post" action="?">
                            <? include 'extra/translators_form.php'; ?> 
                        </form>
                    </div>

                </div>

            </div>
            <!-- /daily sales -->

        </div>
    </div>
    <!-- /dashboard content -->
</div>
<!-- /main content -->



<script type="text/javascript">
<!--
var translator_saved = false;

function uploadFile(form) {
	var button = form.submit;
	button.disabled = true;
	button.value = 'Loading...';
	var file = form.file_contents.files[0];
	var file_name = file.name;
	var agent_id = form.agent_id.value;
	var language_id = form.language_id.value;
	var interpreter_id = form.interpreter_id.value;
	var progress = document.getElementById('progress_'+interpreter_id+'_'+language_id);
//	progress.style.display = 'block';
	var reader = new FileReader();
	reader.readAsBinaryString(file);
	//reader.onloadstart = ...
	reader.onprogress = function(evt, fileName) {
		if (evt.lengthComputable) {
			// evt.loaded and evt.total are ProgressEvent properties
			var progress = Math.round((evt.loaded * 100) / evt.total);
			// Increase the prog bar length
			progress.style.width = (progress * 2) + "px";
			button.value = 'Loading '+progress+'%';
		}
	}; //... <-- Allows you to update a progress bar.
	//reader.onabort = ...
	//reader.onerror = ...
	//reader.onloadend = ...
	reader.onload = function(event) {
    var result = event.target.result;
    $.post('/transp/upload', { 
			data: result, 
			name: file_name,
			language_id: language_id, 
			interpreter_id: interpreter_id 
		}, function(data) {
			//alert(data);
			manageLanguage_real(interpreter_id, agent_id);
		});
  };
	return false;
}

function addlanguage(translator_id,agent,lang_code,button) {
	button.disabled = true;
	$.ajax({
		url: "/transp/addlanguage?translator_id=" + translator_id + "&agent_id=" + agent + "&lang_code=" + lang_code
	}).done(function (data) {
		if (data=='0') {
			manageLanguage_real(translator_id,agent);
		} else {
			alert(data);
		}
		button.disabled = false;
	});
	return false;	
}
function addtranslator() {
	if (translator_saved) {
		$('#action_panel').html($('#action_panel_translator').html());
		translator_saved = false;
		$('#action_panel_translator').html('Error');
	}
	$('#translator_name').html('Add New Translator');
	$('#interpreter_id').val('0');
	$('#email').val('');
	$('#firstname').val('');
	$('#lastname').val('');
  $('#phone').val('');
	$('#street').val('');
	$('#city').val('');
	$('#state').val('GA');
	$('#zipcode').val('');
	return false;
}

function edittranslator(translator_id, agent) {
	if (confirm("Are you sure you want continue ?")) {
// do something
		if (translator_saved) {
			$('#action_panel').html($('#action_panel_translator').html());
			translator_saved = false;
			$('#action_panel_translator').html('Error');
		}
		$.ajax({
			url: "/transp/translators_load?translator_id=" + translator_id + "&agent_id=" + agent
		}).done(function (data) {
			translator = JSON.parse(data)
			if (translator.status==1) {
				$('#translator_name').html('EDIT: '+translator.firstname+' '+translator.lastname+' = '+translator.interpreter_id);
				$('#interpreter_id').val(translator.interpreter_id);
				$('#email').val(translator.email);
				$('#firstname').val(translator.firstname);
				$('#lastname').val(translator.lastname);
  			$('#phone').val(translator.phone);
				$('#street').val(translator.street);
				$('#city').val(translator.city);
				$('#state').val(translator.state);
				$('#zipcode').val(translator.zipcode);
// {"ADDED":"2017-10-13 16:10:39.226379","AGENT_ID":"4","CITY":"MARIETTA","COUNTRY":"US","EMAIL":"SES66181+INTERPRETER76@GMAIL.COM","FIRSTNAME":"ANATOLII","ID":"15","INTERPRETER_ID":"15","LASTNAME":"OKHOTNIKOV","LOC":"104.238.127.115","PHONE":"664651123","PID":"100","STATE":"GA","STATUS":"1","STREET":"2600 BENTLEY RD SE","ZIPCODE":"30067","INTERNAL_RETURN":"0"}			
			} else {
				alert('Failed to load translator!');
				addtranslator();
			}
		});
	}
	return false;
}

    function manageTranslator(line_id, agent) {
        if (confirm("Are you sure you want continue ?")) {
// do something
        } else {
            return false;
        }
        return false;
    }

function manageLanguage(line_id, agent) {
//	if (confirm("Are you sure you want configure translators languages ?")) {
// do something
		
//	}
        
        manageLanguage_real(line_id, agent);
	return false;
}

function manageLanguage_real(line_id, agent) {
	if (translator_saved) {
		// We have saved the translator form, so nothing to do here
	} else {
		$('#action_panel_translator').html($('#action_panel').html());
		translator_saved = true;
	}	
        
  $('#accs'+line_id).prop('disabled', true);
  $.ajax({
         url: "/transp/cfgtranslator?proc=DETAIL&translator_id="+line_id+"&agent_id"+agent
  }).done(function (data) {
      $('#action_panel').html(data);          
      $('#accs'+line_id).prop('disabled', false);
  });
  return false;
}

function manageLanguageStatus(button,interpreter_id,language_id,lang_code) {
  button.disabled = true;
	$.ajax({
		url: "/transp/cfgtranslator?proc=STATUS&translator_id="+interpreter_id+"&language_id="+language_id+"&lang_code="+lang_code+"&status="+button.innerHTML
	}).done(function (data) {
    if (data=='0') {
			if (button.innerHTML=='Enable') {
				button.innerHTML = 'Disable';
				button.className = 'btn btn-danger btn-xs';
			} else {
				button.innerHTML = 'Enable';
				button.className = 'btn btn-primary btn-xs';
			}
		} else {
			alert(data);
		}
		button.disabled = false;
	});
	return false;
}

function manageLanguageFlags(button,interpreter_id,language_id,lang_code) {
	result = false;
  button.disabled = true;
	$.ajax({
		url: "/transp/cfgtranslator?proc=FLAGS&translator_id="+interpreter_id+"&language_id="+language_id+"&lang_code="+lang_code+"&flags="+(button.checked?1:0)
	}).done(function (data) {
    if (data=='0') {
			result = true;
		} else {
			alert(data);
		}
		button.disabled = false;
	});
	return result;
}

// -->
</script>



<!--
vi:ts=2
-->
