<?php
include_once("c_setting_member.php");
class c_page_cab_setting_member_sign extends c_page_cab_setting_member
{
  public $h1='Подпись аккаунта' ;

 function block_main()
 { $this->page_title() ;
   ACCOUNTS()->update_member_info(MEMBER()) ;
   //damp_array($this->rec_member,1,-1) ;
   if ($this->rec_member['_signature_file_name'])
   {?><img src="/public/account/source/<?echo $this->rec_member['_signature_file_name']?>" style="border:1px dotted #272727;"><?}

   $this->panel_person_sign() ;
   ?><br><br><?
   $this->panel_upload_sign() ;
 }

 function panel_upload_sign()
  {
      ?><script src="/AddOns/CustomFileInputs/js/custom-file-input.js"></script>
        <h2>Вариант 2. Загрузите факсимиле подписи из файла изображения</h2>
        <p>Требования к файлу:</p>
            <ul><li>Формат GIF</li>
                <li>прозрачный фон</li>
                <li>рекомендованный размер 300x150px</li>
            </ul>
      <link rel="stylesheet" type="text/css" href="/AddOns/CustomFileInputs/css/demo.css" />
      <link rel="stylesheet" type="text/css" href="/AddOns/CustomFileInputs/css/component.css" />
      <form enctype="multipart/form-data">
      <div id="panel_sign_upload" class="container" style="position:relative;">

            <div class="box2 sky-form">
               <input  style="display:none;" type="file" name="upload_sugnature[]" id="file-1" class="inputfile inputfile-1" data-multiple-caption="{count} files selected" _multiple />
               <label for="file-1" style="float:left;margin-left:0px;" class="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="17" viewBox="0 0 20 17"><path d="M10 0l-5.2 4.9h3.3v5.1h3.8v-5.1h3.3l-5.2-4.9zm9.3 11.5l-3.2-2.1h-2l3.4 2.6h-3.5c-.1 0-.2.1-.2.1l-.8 2.3h-6l-.8-2.2c-.1-.1-.1-.2-.2-.2h-3.6l3.4-2.6h-2l-3.2 2.1c-.4.3-.7 1-.6 1.5l.6 3.1c.1.5.7.9 1.2.9h16.3c.6 0 1.1-.4 1.3-.9l.6-3.1c.1-.5-.2-1.2-.7-1.5z"/></svg> <span>Выбрать файл&hellip;</span></label>
                <input type="submit" style="float:left;margin-left:20px;" class="button" account_id="<?echo $this->rec_member['pkey']?>" value="Загрузить подпись">

          </div>
          <div class="clear"></div>
          <style type="text/css">
          		.sky-form{box-shadow:none;}
          </style>
      </div>
      </form>

      <?
  }

function panel_person_sign()
   { ?><h2>Вариант 1. Распишитесь здесь</h2>
       <!--[if lt IE 9]><script type="text/javascript" src="/AddOns/jSignature/flashcanvas.js"></script><![endif]-->
       <script src="/AddOns/jSignature/jSignature.min.noconflict.js"></script>
       <table id="table_person_sign"><tr><td><div id="signature"></div></td></tr></table>
         <script type="text/javascript">
            $j(document).ready(function() { $j("#signature").jSignature({color:"#00f",'decor-color':'#ffffff',showLine:false,width: '600px', height: '300px'}) ; }) ;

                                                //var sigdiv = $j("#signature")
                                                //sigdiv.jSignature() // inits the jSignature widget.
                      </script>
                      <div class="sky-form">
                           <button style="float:left;margin-left:0;" id="apply_sign" class="button" account_id=<?echo $this->rec_member['pkey']?>>Сохранить подпись</button>&nbsp;&nbsp;&nbsp;
                           <button style="float:left;margin-left:20px;" id="clear_sign" class="button">Очистить</button>
                      </div>
         <div class="clear"></div>
         <style type="text/css">
			#table_person_sign{width:auto;table-layout:auto;}
	        #table_person_sign td{text-align:left;vertical-align:top;padding-right:20px;}
	        #table_person_sign td.item img{border:1px solid #aaaaaa;float:left;}
	        #table_person_sign td.item .name{font-size:16px;font-weight:bold;}
	        #table_person_sign td.item div.org_name{font-size:13px;}
	        #table_person_sign td.item div.otdel_name{font-size:11px;}
	        #table_person_sign td.item div.working_name{font-size:11px;margin-bottom:12px;}
	        #table_person_sign div#signature{width:600px;height:300px;margin-top:20px;background:url("<?echo _PATH_TO_EXT?>/esmo_magnit_instruction/img/kletka.png") repeat;}
         </style>
         <script type="text/javascript">
	         $j('button#apply_sign').on('click',function()
	         {  var sigdiv = $j("#signature")
		        var datapair = sigdiv.jSignature("getData", "image")  ;
		        //alert(datapair);
		        send_ajax_request({cmd:'aspmo_setting/account_save_sign',account_id:<?echo $this->rec_member['pkey']?>,image:datapair}) ;
	         }) ;
	         $j('button#clear_sign').on('click',function()
	         {  var sigdiv = $j("#signature")
		        sigdiv.jSignature("reset") // clears the canvas and rerenders the decor on it.
		        //alert(datapair);
		        //send_ajax_request({cmd:'aspmo_setting/account_save_sign',account_id:<?echo $this->rec_member['pkey']?>,image:datapair}) ;
	         }) ;
         </script>
	   <?
   }

    function CMD_save_member()
    {
       if (_sizeof($_FILES))
       { // загрузка печати


         // загрузка подписи
         $recs_files=conver_FILES_to_recs($_FILES['upload_sugnature']) ;  //damp_array($recs_files) ;
         if (_sizeof($recs_files[0]))
           { if ($recs_files[0]['type']=='image/gif' or 1)
             { ?><h2>Загружаем изображение из файла "<?echo $recs_files[0]['name']?>"</h2><?
               include_once(_DIR_TO_ENGINE.'/admin/i_admin_system.php') ;
               execSQL_update('delete from obj_site_account_image where parent='.$this->rec_member['pkey'].' and alt="signature"') ;
               $res_upload=obj_upload_image($this->rec_member['_reffer'],$recs_files[0],array('view_upload'=>1,'img_alt'=>'signature')) ;
               //damp_array($res_upload) ;
               $res_upload=array('type'=>'success','no_default_panel'=>1) ;
               $res='ok' ;
             }
             else $res_upload=array('type'=>'error','code'=>'failed_type','text'=>'Неверный тип файла. Загрузите файл в формате GIF.') ;
           }


         //else $res_upload=array('type'=>'error','code'=>'not_uploaded_file','text'=>'Не был выбран файл') ;
         if ($res_upload['type']=='error') echo '<div class="alert">'.$res_upload['text'].'</div>' ;
       }
       //else $res_upload=array('type'=>'error','code'=>'not_uploaded_file','text'=>'Не был выбран файл') ;

      //damp_array($_FILES) ;
      if (!$res) echo '<div class="red">Изменений не обнаружено</div>' ;
      else { echo '<div class="green">Данные сохранены</div>' ;
             $this->rec_member=ACCOUNTS()->get_member_by_id($this->rec_member['pkey']) ;
           }
    }

}



?>
