<?php echo $this->partial('Layout/nav'); ?>

<div class="container">
	<div class="container-page-wrapper shodowed bordered">
		<div class="container-page-container">
			<div class="row">
				<div class="col-lg-10">
					<h1><?php echo $this->actionTitle; ?></h1>
					<?php if($this->view->id > 0): ?>
						<small class="text-muted"><?php echo $this->view->survey_domain; ?></small>
					<?php endif; ?>
				</div>
				<div class="col-lg-2 clearfix">
					<div class="float-right">
					
					</div>
				</div>
			</div>
			<hr>
			
			<?php //debug($this->view->survey_domain); ?>
			
			<form id="survey-form-edit">
				<input type="hidden" name="data[id][value]" value="<?php echo $this->view->id; ?>">
				
				<div class="form-row">
				
					<div class="form-group col-lg-3">
						<label class="label-main" for="profile_name"><?php echo _('Name'); ?>*</label>
						<input type="text" class="form-control field-name" value="<?php echo isset($this->view->userData['name']) ? $this->view->userData['name'] : ''; ?>" id="profile_name" name="data[name][value]">
						
						<input type="hidden" name="data[name][required]" value="1">
						<input type="hidden" name="data[name][type]" value="text">
						<input type="hidden" name="data[name][class]" value="field-name">
						<input type="hidden" name="data[name][label]" value="<?php echo _('Name'); ?>">
					</div>
					
					<div class="form-group col-lg-3">
						<label class="label-main" for="profile_surname"><?php echo _('Surname'); ?>*</label>
						<input type="text" class="form-control field-surname" value="<?php echo isset($this->view->userData['surname']) ? $this->view->userData['surname'] : ''; ?>" id="profile_surname" name="data[surname][value]">
						
						<input type="hidden" name="data[surname][required]" value="1">
						<input type="hidden" name="data[surname][type]" value="text">
						<input type="hidden" name="data[surname][class]" value="field-surname">
						<input type="hidden" name="data[surname][label]" value="<?php echo _('Surname'); ?>">
					</div>
					
					<div class="form-group col-lg-3">
						<label class="label-main" for="profile_birthdate"><?php echo _('Birthdate'); ?>*</label>
						<input type="text" class="form-control field-birthdate survey-birthdate" autocomplete="off" value="<?php echo isset($this->view->userData['birthdate']) ? $this->view->userData['birthdate'] : ''; ?>" id="profile_birthdate" name="data[birthdate][value]">
						
						<input type="hidden" name="data[birthdate][required]" value="1">
						<input type="hidden" name="data[birthdate][type]" value="date">
						<input type="hidden" name="data[birthdate][class]" value="field-birthdate">
						<input type="hidden" name="data[birthdate][label]" value="<?php echo _('Birth date'); ?>">
					</div>
					
					<div class="form-group col-lg-3">
						<label class="label-main" for="profile_sex"><?php echo _('Sex'); ?>*</label>
						
						<select class="form-control field-sex" id="profile_sex" name="data[sex][value]">
							<option value="">...</option>
							<option value="f" <?php echo isset($this->view->userData['sex'])&&$this->view->userData['sex']=='f' ? 'selected' : ''; ?>>F</option>
							<option value="m" <?php echo isset($this->view->userData['sex'])&&$this->view->userData['sex']=='m' ? 'selected' : ''; ?>>M</option>
						</select>
						
						<input type="hidden" name="data[sex][required]" value="1">
						<input type="hidden" name="data[sex][type]" value="date">
						<input type="hidden" name="data[sex][class]" value="field-sex">
						<input type="hidden" name="data[sex][label]" value="<?php echo _('Sex'); ?>">
					</div>
					
					<div class="form-group col-lg-6">
						<label class="label-main" for="profile_email"><?php echo _('E-mail'); ?>*</label>
						<input type="email" class="form-control field-email" value="<?php echo isset($this->view->userData['email']) ? $this->view->userData['email'] : ''; ?>" id="profile_email" name="data[email][value]">
						
						<input type="hidden" name="data[email][required]" value="1">
						<input type="hidden" name="data[email][type]" value="email">
						<input type="hidden" name="data[email][class]" value="field-email">
						<input type="hidden" name="data[email][label]" value="<?php echo _('E-mail'); ?>">
					</div>
					
					<div class="form-group col-lg-6">
						<label class="label-main" for="profile_phone">Telefono*</label>
						<input type="tel" class="form-control field-phone" value="<?php echo isset($this->view->userData['phone']) ? $this->view->userData['phone'] : ''; ?>" id="profile_phone" name="data[phone][value]">
						
						<input type="hidden" name="data[phone][required]" value="0">
						<input type="hidden" name="data[phone][type]" value="text">
						<input type="hidden" name="data[phone][class]" value="field-phone">
						<input type="hidden" name="data[phone][label]" value="Telefono">
					</div>
					
					<div class="form-group col-lg-6">
						<label class="label-main" for="profile_cf">Codice fiscale</label>
						<input type="tel" class="form-control field-cf" value="<?php echo isset($this->view->userData['cf']) ? $this->view->userData['cf'] : ''; ?>" id="profile_cf" name="data[cf][value]">
						
						<input type="hidden" name="data[cf][required]" value="0">
						<input type="hidden" name="data[cf][type]" value="text">
						<input type="hidden" name="data[cf][class]" value="field-phone">
						<input type="hidden" name="data[cf][label]" value="Codice fiscale">
					</div>
					
					<div class="form-group col-lg-12">
						<hr>
					</div>
					
					<div class="form-group col-lg-6">
						
						<div class="form-check">
							<input class="form-check-input check-auto-tlc" type="radio" value="1" id="check-auto-tlc-new" name="data[autotlc][value]" <?php echo !isset($this->view->userData['remote_auto_tlc']) || isset($this->view->userData['remote_auto_tlc'])&&(int)$this->view->userData['remote_auto_tlc']==1 ? 'checked' : ''; ?> <?php echo $this->view->is_linked ? 'disabled' : ''; ?>>
							<label class="form-check-label" for="check-auto-tlc-new">
								Crea una nuova televisita associata a questo nuovo paziente 
								
								<?php if(isset($this->view->userData['remote_auto_tlc_id'])&&(int)$this->view->userData['remote_auto_tlc_id']>0): ?>
									<span class="badge badge-info"><i class="fa fa-check" aria-hidden="true"></i> #<?php echo $this->view->userData['remote_auto_tlc_id']; ?></span>
								<?php endif; ?>
								
								<?php if((isset($this->view->userData['remote_auto_tlc'])&&(int)$this->view->userData['remote_auto_tlc']==1) && (isset($this->view->userData['remote_auto_tlc_id'])&&(int)$this->view->userData['remote_auto_tlc_id']==0)): ?>
								<div class="text-muted margin-bottom-10"><small>L'ID della nuova televisita sarà associato quando il paziente risponderà al questionario.</small></div>
								<?php endif; ?>
							</label>
						</div>
						
						<div class="form-check">
							<input class="form-check-input check-auto-tlc" type="radio" value="2" id="check-auto-tlc-exists" name="data[autotlc][value]" <?php echo isset($this->view->userData['remote_auto_tlc'])&&(int)$this->view->userData['remote_auto_tlc']==2 ? 'checked' : ''; ?> <?php echo $this->view->is_linked ? 'disabled' : ''; ?>>
							<label class="form-check-label" for="check-auto-tlc-exists">
								Associa questo paziente a una televisita esistente 
							</label>
						</div>
					</div>
					
					<div class="form-group col-lg-6">
						<div class="auto-tlc-id <?php echo !isset($this->view->userData['remote_auto_tlc'])||(isset($this->view->userData['remote_auto_tlc'])&&$this->view->userData['remote_auto_tlc']==1) ? 'hide-control' : ''; ?>">
							<label class="label-main" for="profile_tlc_number">#ID televisita</label>
							<input type="number" class="form-control " value="<?php echo isset($this->view->userData['remote_auto_tlc_id'])&&(int)$this->view->userData['remote_auto_tlc_id']>0 ? (int)$this->view->userData['remote_auto_tlc_id'] : ''; ?>" id="profile_tlc_number" name="data[tlcid][value]" min="1" <?php echo $this->view->is_linked ? 'disabled' : ''; ?>>
							<!--<small class="text-muted">Indicare l'ID di un teleconsulto esistente.</small>-->
						</div>
					</div>
					
					<div class="form-group col-lg-12">
						<hr>
					</div>
					
					<!--
					<div class="form-group col-lg-12">
						<label class="label-main" for="request_delay_date">Data ricezione</label>
						
						<input type="text" class="form-control field-delay_date survey-delay_date" autocomplete="off" value="<?php echo isset($this->view->userData['msg_delay_at']) ? $this->view->userData['msg_delay_at'] : ''; ?>" id="profile_delay_date" name="data[delay_date][value]">
						
						<input type="hidden" name="data[delay_date][required]" value="0">
						<input type="hidden" name="data[delay_date][type]" value="text">
						<input type="hidden" name="data[delay_date][class]" value="field-request_delay_date">
						<input type="hidden" name="data[delay_date][label]" value="Data ricezione">
					</div>
					-->
					
					<div class="form-group col-lg-12">
						<label class="label-main" for="request_medremarks"><?php echo _('Note'); ?></label>
						<textarea class="form-control field-request_medremarks" name="data[request_medremarks][value]" rows="4"><?php echo isset($this->view->userData['notes']) ? strip_tags($this->view->userData['notes']) : ''; ?></textarea>
						<p class="text-muted"><small><b>Attenzione:</b> il testo riportato in questo campo comparirà nel referto inviato al paziente.</small></p>
						
						<input type="hidden" name="data[request_medremarks][required]" value="1">
						<input type="hidden" name="data[request_medremarks][type]" value="text">
						<input type="hidden" name="data[request_medremarks][class]" value="field-request_medremarks">
						<input type="hidden" name="data[request_medremarks][label]" value="<?php echo _('Note'); ?>">
					</div>
					
					<div class="form-group col-lg-12">
					<hr>
					</div>
					
					<div class="form-group col-lg-12">	
						
						<div class="custom-control custom-radio" style="margin-bottom: 15px;">
							<input type="radio" id="customRadio1" name="customRadio" class="custom-control-input" <?php echo !isset($this->view->userData['msg_delay_at']) || (isset($this->view->userData['msg_delay_at']) && trim($this->view->userData['msg_delay_at'])=='') ? 'checked' : ''; ?>>
							<label class="custom-control-label" for="customRadio1">Invia il questionario subito</label>
						</div>
						<div class="custom-control custom-radio">
							<input type="radio" id="customRadio2" name="customRadio" class="custom-control-input" <?php echo isset($this->view->userData['msg_delay_at']) ? 'checked' : ''; ?>>
							<label class="custom-control-label" for="customRadio2">Invia il questionario in data: <input type="text" class="form-control field-delay_date survey-delay_date" autocomplete="off" value="<?php echo isset($this->view->userData['msg_delay_at']) ? $this->view->userData['msg_delay_at'] : ''; ?>" id="profile_delay_date" name="data[delay_date][value]" style="display: inline-block; width: 200px; margin-top: -6px;"></label>
						</div>

					</div>
					
					<div class="form-group col-lg-12">
						<hr>
					</div>
					
					<div class="form-group col-lg-9">
						<label class="label-main" for="survey_type_list">Tipo questionario*</label>
						
						<select class="form-control field-survey_types" id="survey_type_list" name="data[survey_type][value]">
							<option value="0">...</option>
							<?php foreach($this->view->survey_type_list as $id => $label): ?>
								<?php
									$selected = '';
									if (isset($this->view->userData['type_id'])) {
										$selected = $this->view->userData['type_id']==$id ? 'selected' : '';
									}
									
									if (count($this->view->survey_type_list) == 1) {
										$selected = 'selected';
									}
								?>
								<option value="<?php echo $id; ?>" <?php echo $selected; ?>><?php echo $label; ?></option>
							<?php endforeach; ?>
						</select>
						<input type="hidden" name="data[survey_type][class]" value="field-survey_types">
					</div>
					
					<div class="form-group col-lg-3">
						<button type="button" class="btn btn-info btn-block btn-edit-survey-preview" style="margin-top:31px;">Anteprima</button>
					</div>
					
				</div>
				
				<hr>
								
				<div class="clearfix">
					<?php if(is_array($this->view->survey_type_list) && !empty($this->view->survey_type_list)): ?>
						<div class="float-right">
							<button type="button" class="btn btn-secondary btn-edit-survey" data-op="saveonly">Salva</button>
							<button type="button" class="btn btn-primary btn-edit-survey" data-op="savensend">Salva e invia</button>
						</div>
					<?php else: ?>
						<div class="alert alert-danger">Impossibile inviare la Televisita: l'utente corrente non ha nessun questionario assegnato.</div>
					<?php endif; ?>
				</div>
					
			</form>
			
		</div>
	</div>
</div>

<div class="modal" id="dialog-survey-preview" tabindex="-1" role="dialog">
  <div class="modal-dialog modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">Anteprima televisita</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        	<div class="text-center" id="dialog-loader"><img src="<?php echo $this->layout->getPublicUri(); ?>images/ajaxloader.svg" width="50"></div>
			<div class="modal-body-survey-preview"></div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-primary" data-dismiss="modal"><?php echo _('Close'); ?></button>
      </div>
    </div>
  </div>
</div>