<?php /* Smarty version Smarty-3.1.11, created on 2023-09-02 13:40:17
         compiled from "../views/obgy/reserve_clinic/clinics.html" */ ?>
<?php /*%%SmartyHeaderCode:85070666164d20e877205e3-39262581%%*/if(!defined('SMARTY_DIR')) exit('no direct access allowed');
$_valid = $_smarty_tpl->decodeProperties(array (
  'file_dependency' => 
  array (
    'a993f094c597973b886ec7d8bb4a775e9b93264a' => 
    array (
      0 => '../views/obgy/reserve_clinic/clinics.html',
      1 => 1678982940,
      2 => 'file',
    ),
  ),
  'nocache_hash' => '85070666164d20e877205e3-39262581',
  'function' => 
  array (
  ),
  'version' => 'Smarty-3.1.11',
  'unifunc' => 'content_64d20e8778bdb7_44005449',
  'variables' => 
  array (
    'doctorName' => 0,
    'clinics' => 0,
    'i' => 0,
    'row' => 0,
    'hosturl' => 0,
  ),
  'has_nocache_code' => false,
),false); /*/%%SmartyHeaderCode%%*/?>
<?php if ($_valid && !is_callable('content_64d20e8778bdb7_44005449')) {function content_64d20e8778bdb7_44005449($_smarty_tpl) {?><div class="modal fade" tabindex="-1" role="dialog" aria-hidden="false" data-backdrop="static" data-keyboard="false" 
     id="displayClinicsModel" style="min-width:1000px;">
    <div class="modal-dialog  modal-lg wds90">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close endRooms" data-dismiss="modal" aria-hidden="true"></button>
                <h4 class="modal-title txtc"> <?php echo $_smarty_tpl->tpl_vars['doctorName']->value;?>
 </h4>
            </div>
            <div class="modal-body">
                <div class="portlet-body form">
                    <form class="form-horizontal" role="form" action="" method="post" id="gynaDrugs" enctype="multipart/form-data">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="portlet blue-hoki box">

                                    <div class="portlet-body  scroll_y showNum isheight">
                                        <input type="hidden" id="hasRecord" value="1" />
                                        <input type="hidden" name="dirName" id="dirName"   value="clinicrecords"/>
                                        <table class="table table-striped table-hover table-bordered" style="direction: rtl;margin: 2%; width: 96%;">
                                            <caption>
                                                <a href="javascript:;"  id="new_room"
                                                   class="btn green-haze btn-block btn-xs fleft wds10">إضافة جديد   </a>
                                            </caption>
                                            <thead>
                                                <tr>
                                                    <th class="wds3 txtc">م</th>
                                                    <th class="txtc">اسم الغرفة </th>
                                                    <th class="txtc">رقم  الغرفة </th>
                                                    <th class="wds5">  </th>
                                                    <th class="wds10">  </th>
                                                </tr>
                                            </thead>
                                            <tbody id="roomsContainer">
                                                <?php $_smarty_tpl->tpl_vars['i'] = new Smarty_variable(1, null, 0);?>
                                                <?php  $_smarty_tpl->tpl_vars['row'] = new Smarty_Variable; $_smarty_tpl->tpl_vars['row']->_loop = false;
 $_from = $_smarty_tpl->tpl_vars['clinics']->value; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array');}
foreach ($_from as $_smarty_tpl->tpl_vars['row']->key => $_smarty_tpl->tpl_vars['row']->value){
$_smarty_tpl->tpl_vars['row']->_loop = true;
?>
                                                <tr>
                                                    <td> <?php echo $_smarty_tpl->tpl_vars['i']->value;?>
</td>
                                                    <td>
                                                        <input type="text" class="form-control updateElement" data-id="<?php echo $_smarty_tpl->tpl_vars['row']->value['id'];?>
" 
                                                               data-colName="name" data-tableName="clinic_rooms" value="<?php echo $_smarty_tpl->tpl_vars['row']->value['name'];?>
" 
                                                               data-toggle="popover" data-trigger="hover" data-placement="bottom" 
                                                               data-content="<?php echo $_smarty_tpl->tpl_vars['row']->value['name'];?>
"/>
                                                    </td>
                                                    <td>
                                                        <input type="text" class="form-control updateElement" data-id="<?php echo $_smarty_tpl->tpl_vars['row']->value['id'];?>
" 
                                                               data-colName="clinic_no" data-tableName="clinic_rooms" value="<?php echo $_smarty_tpl->tpl_vars['row']->value['clinic_no'];?>
" 
                                                               data-toggle="popover" data-trigger="hover" data-placement="bottom" 
                                                               data-content="<?php echo $_smarty_tpl->tpl_vars['row']->value['clinic_no'];?>
"/>
                                                    </td>
                                                    <td>
                                                        <input type="checkbox" data-colName="today_list" data-tableName="clinic_rooms"   
                                                               value="1"  class="form-control updateElementCheck" 
                                                               data-id="<?php echo $_smarty_tpl->tpl_vars['row']->value['id'];?>
"  <?php if ($_smarty_tpl->tpl_vars['row']->value['today_list']==1){?>  checked   <?php }?> >
                                                    </td>
                                                    <td>
                                                        <?php if ($_smarty_tpl->tpl_vars['row']->value['voiceRecord']==1){?> 
                                                        <audio controls  src="<?php echo $_smarty_tpl->tpl_vars['hosturl']->value;?>
/../upload/clinicrecords/<?php echo $_smarty_tpl->tpl_vars['row']->value['id'];?>
.wav"> </audio>
                                                        <?php }?>
                                                    </td>
                                                </tr>
                                                <?php $_smarty_tpl->_capture_stack[0][] = array('default', 'i', null); ob_start(); ?><?php echo $_smarty_tpl->tpl_vars['i']->value+1;?>
<?php list($_capture_buffer, $_capture_assign, $_capture_append) = array_pop($_smarty_tpl->_capture_stack[0]);
if (!empty($_capture_buffer)) {
 if (isset($_capture_assign)) $_smarty_tpl->assign($_capture_assign, ob_get_contents());
 if (isset( $_capture_append)) $_smarty_tpl->append( $_capture_append, ob_get_contents());
 Smarty::$_smarty_vars['capture'][$_capture_buffer]=ob_get_clean();
} else $_smarty_tpl->capture_error();?>
                                                <?php } ?>
                                            </tbody>
                                        </table>




                                        <div class="form-actions col-md-12">
                                            <div class="col-md-5">
                                                <div id="controls" style="    margin-top: 0;">
                                                    <button class="recordButtom" id="recordButton">Record</button>
                                                    <button class="recordButtom" id="pauseButton" disabled>Pause</button>
                                                    <button class="recordButtom" id="stopButton" disabled>Stop</button>
                                                </div>

                                                <!--div id="formats">Format: start recording to see sample rate</div-->
                                            </div>

                                            <div class="col-md-3">
                                                <select class="select2h" style="width: 100%;"  id="ptntid" 
                                                        placeholder="اختر " required >
                                                    <option value=""></option>
                                                    <?php  $_smarty_tpl->tpl_vars['row'] = new Smarty_Variable; $_smarty_tpl->tpl_vars['row']->_loop = false;
 $_from = $_smarty_tpl->tpl_vars['clinics']->value; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array');}
foreach ($_from as $_smarty_tpl->tpl_vars['row']->key => $_smarty_tpl->tpl_vars['row']->value){
$_smarty_tpl->tpl_vars['row']->_loop = true;
?>
                                                    <option value="<?php echo $_smarty_tpl->tpl_vars['row']->value['id'];?>
"><?php echo $_smarty_tpl->tpl_vars['row']->value['name'];?>
</option>
                                                    <?php } ?>
                                                </select>
                                            </div>

                                            <div class="col-md-4 fright">
                                                <p><strong>Voice Record:</strong></p>
                                                <ol id="recordingsList">  </ol>
                                            </div>
                                        </div>


                                    </div>
                                </div>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn default endRooms" id="closemodel" data-dismiss="modal"> Close</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>



<script>
    $("#ptntid").select2();

//webkitURL is deprecated but nevertheless
    URL = window.URL || window.webkitURL;
    var hosturl = $('#hosturl').val();
    var gumStream; 						//stream from getUserMedia()
    var rec; 							//Recorder.js object
    var input; 							//MediaStreamAudioSourceNode we'll be recording

// shim for AudioContext when it's not avb. 
    var AudioContext = window.AudioContext || window.webkitAudioContext;
    var audioContext //audio context to help us record

    var recordButton = document.getElementById("recordButton");
    var stopButton = document.getElementById("stopButton");
    var pauseButton = document.getElementById("pauseButton");

//add events to those 2 buttons
    recordButton.addEventListener("click", startRecording);
    stopButton.addEventListener("click", stopRecording);
    pauseButton.addEventListener("click", pauseRecording);

    function startRecording() {
        console.log("recordButton clicked");

        /*
         Simple constraints object, for more advanced audio features see
         https://addpipe.com/blog/audio-constraints-getusermedia/
         */

        var constraints = {audio: true, video: false}

        /*
         Disable the record button until we get a success or fail from getUserMedia() 
         */

        recordButton.disabled = true;
        stopButton.disabled = false;
        pauseButton.disabled = false

        /*
         We're using the standard promise based getUserMedia() 
         https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia
         */

        navigator.mediaDevices.getUserMedia(constraints).then(function (stream) {
            console.log("getUserMedia() success, stream created, initializing Recorder.js ...");

            /*
             create an audio context after getUserMedia is called
             sampleRate might change after getUserMedia is called, like it does on macOS when recording through AirPods
             the sampleRate defaults to the one set in your OS for your playback device
             */
            audioContext = new AudioContext();

            //update the format 
            //    document.getElementById("formats").innerHTML = "Format: 1 channel pcm @ " + audioContext.sampleRate / 1000 + "kHz"

            /*  assign to gumStream for later use  */
            gumStream = stream;

            /* use the stream */
            input = audioContext.createMediaStreamSource(stream);

            /* 
             Create the Recorder object and configure to record mono sound (1 channel)
             Recording 2 channels  will double the file size
             */
            rec = new Recorder(input, {numChannels: 1})

            //start the recording process
            rec.record()

            console.log("Recording started");

        }).catch(function (err) {
            //enable the record button if getUserMedia() fails
            recordButton.disabled = false;
            stopButton.disabled = true;
            pauseButton.disabled = true
        });
    }

    function pauseRecording() {
        console.log("pauseButton clicked rec.recording=", rec.recording);
        if (rec.recording) {
            //pause
            rec.stop();
            pauseButton.innerHTML = "Resume";
        } else {
            //resume
            rec.record()
            pauseButton.innerHTML = "Pause";

        }
    }

    function stopRecording() {
        console.log("stopButton clicked");

        //disable the stop button, enable the record too allow for new recordings
        stopButton.disabled = true;
        recordButton.disabled = false;
        pauseButton.disabled = true;

        //reset button just in case the recording is stopped while paused
        pauseButton.innerHTML = "Pause";

        //tell the recorder to stop the recording
        rec.stop();

        //stop microphone access
        gumStream.getAudioTracks()[0].stop();

        //create the wav blob and pass it on to createDownloadLink
        rec.exportWAV(createDownloadLink);
    }

    function createDownloadLink(blob) {

        var url = URL.createObjectURL(blob);
        var au = document.createElement('audio');
        var li = document.createElement('li');
        var link = document.createElement('a');
        //name of .wav file to use during upload and download (without extendion)
        var filename = 'voice_record';
        //   new Date().toISOString();
        //add controls to the <audio> element
        au.controls = true;
        au.src = url;
        au.style.width = "75%";
        au.style.display = "inline-block";
        //save to disk link
        link.href = url;
        link.download = filename + ".wav"; //download forces the browser to donwload the file using the  filename
        link.innerHTML = "Save to disk";
        //add the new audio element to li
        li.appendChild(au);
        //add the filename to the li
        // li.appendChild(document.createTextNode(filename + ".wav "));

        //add the save to disk link to li
        // li.appendChild(link);
        //upload link
        var upload = document.createElement('a');
        upload.href = "#";
        upload.innerHTML = "Upload";
        upload.classList.add("btn");
        upload.classList.add("green");
        upload.classList.add("mb-50");
        upload.addEventListener("click", function (event) {
            var xhr = new XMLHttpRequest();
            xhr.onload = function (e) {
                if (this.readyState === 4) {
                    console.log("Server returned: ", e.target.responseText);
                }
            };
            var fd = new FormData();
            fd.append("audio_data", blob, filename);
            //    alert($('#ptntid').val());
            fd.append("fileName", $('#ptntid').val());
            fd.append("dirName", $('#dirName').val());
            if ($('#dirName').val() == 'clinicrecords' && !($('#ptntid').val() > 0)) {
                alert(' اختر العيادة أولا ');
            } else {
                xhr.open("POST", hosturl + '/controllers/patients.php?ac=uploadRecord', true);
                xhr.send(fd);
            }
        })
        li.appendChild(document.createTextNode(" "))//add a space in between
        li.appendChild(upload)//add the upload link to li

        //add the li element to the ol
        $('#recordingsList').html('');
        recordingsList.appendChild(li);
    }

</script>

<?php }} ?>