<?php
require_once __DIR__.'/../include/autoload.php';
require_once __DIR__.'/../include/Page.Class.php';
require_once __DIR__.'/../include/MYB.Class.php';

$title="Users";

$Page = new Page();
$Page->Title = $title;
$Page->SetIcon('pie_chart');
$MYB = new MYBrokerage();

$param      = array_to_obj($param);
$id         = $param->id;

if(!$id) $id = $User->id;
$UserData = Get_User_Info('id', $id, false);

$force_uid = '';
if($UserData->id !== $User->id && is_backoffice() && $UserData->company_id == $User->company_id){
	$force_uid = "?uid={$UserData->id}";
}



$Body = <<<EOD
<div class="profile-header">
   <div class="row">
      <div class="col">
         <div class="profile-img">
            <img src="{$Page->BASE_URL_HTTPS}/assets/images/avatars/profile-image-1.png">
         </div>
         <div class="profile-name">
            <h3 style="color:#000">{$UserData->name}</h3>
            <span>{$UserData->job_title}</span>
            <span style="margin-top:0">ACCOUNT {$UserData->role}</span>
         </div>
         
      </div>
   </div>
</div>
<div class="profile-content">
<div class="row">
   <div class="col-md-8">
      <div class="card">
         <div class="card-header">
            <ul class="nav nav-tabs card-header-tabs" role="tablist">
               <li class="nav-item">
                  <a class="nav-link active"  data-toggle="tab" href="#nav-setup" role="tab">INFO BASE ACCOUNT</a>
               </li>
               <li class="nav-item">
                  <a class="nav-link"  data-toggle="tab" href="#nav-tech" role="tab">INFO TECNICHE</a>
               </li>
               
               <li class="nav-item">
                  <a class="nav-link"  data-toggle="tab" href="#nav-bio" role="tab">TESTI PERSONALI</a>
               </li>
                <li class="nav-item">
                  <a class="nav-link"  data-toggle="tab" href="#nav-pswd" role="tab">CAMBIO PASSWORD</a>
               </li>
            </ul>
         </div>
         <div class="card-body">
            <form method="post" action="" enctype="multipart/form-data" id="sendform">
               <div class="tab-content" id="nav-tabContent">
                  <div class="tab-pane fade show active" id="nav-setup" role="tabpanel">
                     <div class="row">
                        <div class="form-group col-md-4">
                           <label for="name">Nome e Cognome</label>
                           <input autocomplete="false" value="{$UserData->name}" placeholder="Mario Rossi" required type="text" class="form-control" name="name" />
                        </div>
                        <div class="form-group col-md-4">
                           <label for="name">Email</label>
                           <input autocomplete="false" value="{$UserData->email}" required type="email" class="form-control" name="email" />
                        </div>
                        <div class="form-group col-md-4">
                           <label for="tel">Tel. / Cell.</label>
                           <input placeholder="347121234" required  type="text" class="form-control" id="tel" name="cell" value="{$UserData->cell}"/>
                        </div>
                     </div>

                     <div class="row">
                        <div class="form-group col-4">
                           <label>Piano Provvigionale (%)</label>
                           <input type="text" class="form-control" name="piano" value="{$UserData->piano}"/>
                        </div>
                        <div class="form-group col-4">
                           <label>Data Contratto</label>
                           <input type="date" class="form-control" name="data_contratto" value="{$UserData->data_contratto}"/>
                        </div>
                        <div class="form-group col-md-4">
                        <label>Unità Organizzativa</label>
                        
                           {$fn(input_select('org_unit_id',$OrgUnitsValues,$UserData->org_unit_id,'select2'))}
                        
                        </div>
                     </div>
                     <hr/>
                     <div class="row">
                        <div class="form-group col-4" style="display:none">
                           <label>Obiettivo Giornaliero (notizie)</label>
                           <input type="text" class="form-control" name="daily_target" value="{$UserData->daily_target}"/>
                        </div>
                     </div>
                     <div class="row">

                        <div class="form-group col-md-4">
                           <label>Ruolo</label>
                           
                           {$fn(input_select('job_title',$JobTitle_Values,$UserData->job_title,'select2'))}
                           
                        </div>
                       
                        <div class="form-group col-md-4">
                           <label>Tipo Account</label>
                           
                           {$fn(input_select('role',$Role_Values,$UserData->role,'select2'))}
                           
                        
                        </div>
                        <div class="form-group col-md-4">
                           <label>Assegnato a Team Leader</label>
                           
                           {$fn(input_select('team_leader_id',$TL_Values,$UserData->team_leader_id,'select2'))}
                           
                        
                        </div>
                     </div>
                     <button class="btn btn-block btn-primary m-t-lg" type="button" onclick="ApiRequest('user',{$id},'edit','#sendform')">Salva</button>
                  </div>
                  <div class="tab-pane fade" id="nav-tech" role="tabpanel">
                     <div class="row" >
                        <div class="form-group col-3" style="display:none">
                           <label>ID CRM</label>
                           <input type="text" class="form-control" name="crm_id" value="{$UserData->crm_id}"/>
                        </div>
                        <div class="form-group col-3">
                           <label>ID Telegram</label>
                           <input type="text" class="form-control" name="telegram_id" value="{$UserData->telegram_id}"/>
                        </div>
                        <div class="form-group col-3">
                           <label>ID Utente Gestionale</label>
                           <input type="text" class="form-control" name="maximizer_uid" value="{$UserData->maximizer_uid}"/>
                        </div>
                        <div class="form-group col-3">
                        <label>Google Calendar Sync</label><br/>
                        {$UserData->gcalendar_sync_field}
                     </div>
                     </div>
                     <button class="btn btn-block btn-primary m-t-lg" type="button" onclick="ApiRequest('user',{$id},'edit','#sendform')">Salva</button>
                  </div>
                  
		  
                  <div class="tab-pane fade" id="nav-bio" role="tabpanel">
                    <div class="row">
                        <div class="form-group col-md-12">
                           <label>La tua Citazione preferita</label>
                           <input class="form-control" name="quote" value="{$UserData->quote}"/>
                        </div>
                     </div>

                     <div class="row">
                        <div class="form-group col-md-12">
                           <label>Bio e Carriera</label>
                           <textarea class="form-control" name="carriera_content">{$UserData->carriera_content}</textarea>
                        </div>
                     </div>
                     <div class="row">
                        <div class="form-group col-md-12">
                           <label>Cosa mi piace di questo lavoro...</label>
                           <textarea class="form-control" name="mipiace_content">{$UserData->mipiace_content}</textarea>
                        </div>
                     </div>
                     <div class="row">
                        <div class="form-group col-4">
                           <label>Hobbies</label>
                           <textarea class="form-control" name="hobbies_content">{$UserData->hobbies_content}</textarea>
                        </div>
                        <div class="form-group col-4">
                           <label>Corsi</label>
                           <textarea class="form-control" name="corsi_content">{$UserData->corsi_content}</textarea>
                        </div>
                        <div class="form-group col-4">
                           <label>Premi e Riconoscimenti</label>
                           <textarea class="form-control" name="awards_content">{$UserData->awards_content}</textarea>
                        </div>
                     </div>
                     <button class="btn btn-block btn-primary m-t-lg" type="button" onclick="ApiRequest('user',{$id},'edit','#sendform')">Salva</button>
                  </div>
                   </form>
                   
                  <div class="tab-pane fade" id="nav-pswd" role="tabpanel">
                   <form method="post" action="" enctype="multipart/form-data" id="sendform_pswd">
                     <div class="row" >
                        <div class="form-group col-4">
                           <label>Nuova Password</label>
                           <input type="password" class="form-control" name="new_pswd" value=""/>
                        </div>
                        <div class="form-group col-4">
                           <label>Ripeti Nuova Password</label>
                           <input type="password" class="form-control" name="new_pswd_verify" value=""/>
                        </div>

                     </div>
                     <button class="btn btn-block btn-primary m-t-lg" type="button" onclick="ApiRequest('user',{$id},'edit','#sendform_pswd')">Aggiorna Password</button>
                    </div>
                  
                  
                </div>
                  
           
            </div>
         </div>
      </div>
      <div class="col-md-4">
         <div class="card">
            <div class="card-body">
               <h5 class="card-title">Modifiche Profilo</h5>
               <ul class="list-unstyled profile-about-list">
                  <li>
                         <a href="#" class="btn btn-primary btn-lg btn-block" role="button" aria-disabled="true" onclick="ApiRequestDirectValues('user',{$id},'disable','status=0', 'Accesso disattivato con successo.')">Disattiva Accesso</a>
                    
                  </li>
               </ul>
            </div>
         </div>
         <div class="card">
            <div class="card-body">
               <h5 class="card-title">Info di Contatto</h5>
               <ul class="list-unstyled profile-about-list">
                  <li><i class="material-icons">mail_outline</i><span>{$UserData->email}</span></li>
                  <li><i class="material-icons">local_phone</i><span>{$UserData->cell}</span></li>
               </ul>
            </div>
         </div>
      </div>
   </div>
</div>
EOD;

$Page->AddToFooter = <<<EOD
<script>
CKEDITOR.replace( 'mipiace_content' );

</script>

EOD;
echo $Page->Output($Body);

?>
