<?php
/**
 * 活动列表-数据详情-时长录入完成
 * $Id: event_input_time_result.php,v 1.1 2020/01/03 11:18:46  Exp $
 * @author lixq
 * @package manager.public_html
 */
// 底层包含
require_once("manager_include.inc");

// 登录检查
require_once("check_login.inc");

// 权限检查
if (!checkAuthority("14")) {
	// エラー表示
	$layout_pages = array();
	$layout_pages["left"] = "menu.inc";
	$layout_pages["right"] = "error.inc";
	$message = "权限不足，请联系系统管理员。";
	require_once(MANAGER_TEMPLATE_DIR_PATH . "/layout/leftmenu_layout.inc");
	exit;
}

// 参数取得
$event_id = ParamUtil::getRequestString("event_id");
$ids = ParamUtil::getRequestString("ids");
$comment = ParamUtil::getRequestString("comment");
$time_length = ParamUtil::getRequestString("time_length");

$base64 = ParamUtil::getRequestArray("base64", array());

$image_url = "";
if (count($base64) > 0) {
  $aliHandler = new AliUploadHandler();
  for ($i = 0;$i<count($base64);$i++){
    $json = json_decode($base64[$i],true);
    
    $imgBase64 = $json["base64data"];
    $file_name = $json["filename"];
    $file_size = $json["filesize"];
    
    $new_file = UPLOAD_TMP_DIR . "/" .$file_name;
    if (preg_match('/^(data:\s*image\/(\w+);base64,)/',$imgBase64,$res)) {
      if (file_put_contents($new_file,base64_decode(str_replace($res[1],'', $imgBase64)))) {
      
        $url = $aliHandler->uploadImg($file_name,$new_file);
        if(strpos($url, "http") === 0){
          $image_url .= $url;
          $image_url .= "|";
        }
      }
      @unlink($new_file);
    }
  }
}
if(!empty($image_url)){
  $image_url = substr($image_url,0,strlen($image_url)-1);
}
$id_arr = explode(",", $ids);
foreach ($id_arr as $id){
  $volunteer_event_member_dat = VolunteerEventMemberDat::getById($id);
  if(empty($volunteer_event_member_dat)){
    continue;
  }
  $volunteer_event_member_dat->comment = $comment;
  $volunteer_event_member_dat->time_length = $time_length;
  $volunteer_event_member_dat->images = $image_url;
  $volunteer_event_member_dat->status = "TIME";
  $volunteer_event_member_dat->save();
}


// 页面表示
$layout_pages = array();
$layout_pages["left"] = "menu.inc";
$layout_pages["right"] = "event_input_time_result.inc";
$layout_pages["menu_clicked"] = "3-1";
require_once(MANAGER_TEMPLATE_DIR_PATH . "/layout/leftmenu_layout.inc");
exit;