function upsertHwr($db, $file_id, $hwr_list, $image_output_path) { // 手書きデータの id 取得。 $sql = getSQLBaseForFilehwrList(); $sql .= " AND file_hwr.file_id = :file_id"; $params = array(); $params[':file_id'] = $file_id; $stmt = $db->prepare($sql); $stmt->execute($params); $saved_hwr_list = array(); foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) { $saved_hwr_list[$row['mark_position_y']] = $row; } foreach ($hwr_list as $index => $hwr) { $hwr_val = $hwr['hwr_val']; $update_time = date("Y-m-d H:i:s", $hwr['update_time']); $mark_position_y = isset($hwr['mark_position_y']) ? $hwr['mark_position_y'] : '0'; $hwr_image = array_key_exists('hwr_image', $hwr) ? $hwr['hwr_image'] : null; if (array_key_exists('hwr_id', $hwr)) { $hwr_id = $hwr['hwr_id']; // --- TBL: hwr $rslt = updHwr($db, $hwr_id, $hwr_val, $update_time); if (!$rslt) { \Sop\Log::error(__FILE__, __LINE__, 'Failed to update hwr.'); $msg001 = "The update failed.: hwr"; // 更新に失敗しました: hwr \Sop\Api::exitWithError(array($msg001)); } } else { if (array_key_exists($mark_position_y, $saved_hwr_list)) { $hwr_id = $saved_hwr_list[$mark_position_y]['hwr_id']; // --- TBL: hwr $rslt = updHwr($db, $hwr_id, $hwr_val, $update_time); if (!$rslt) { \Sop\Log::error(__FILE__, __LINE__, 'Failed to update hwr.'); $msg002 = "The update failed.: hwr"; // 更新に失敗しました: hwr \Sop\Api::exitWithError(array($msg002)); } } else { // insert // --- TBL: hwr $hwr_id = -1; $rslt = addHwr($db, $hwr_id, $hwr_val, $update_time, $mark_position_y); if (!$rslt) { \Sop\Log::error(__FILE__, __LINE__, 'Failed to add hwr.'); $msg003 = "The registration failed.: hwr"; // 登録に失敗しました: hwr \Sop\Api::exitWithError(array($msg003)); } $hwr_id = getLastId($db); // --- TBL: file_hwr $rslt = addFilehwr($db, $file_id, $hwr_id); if (!$rslt) { \Sop\Log::error(__FILE__, __LINE__, 'Failed to add file_hwr.'); $msg004 = "The registration failed.: file_hwr"; // 登録に失敗しました: file_hwr \Sop\Api::exitWithError(array($msg004)); } } } // --------------------------- // 手書きの画像をファイルに書き出す。 // --------------------------- if ($hwr_image != null) { $file_path = $image_output_path . '/' . $file_id . '_' . $hwr_id . '.png'; $hwr_image = preg_replace('#^data:image/png;base64,#', '', $hwr_image); $hwr_image = base64_decode($hwr_image); file_put_contents($file_path, $hwr_image); } } }
// --------------------------- $db->beginTransaction(); $date = date("Y-m-d H:i:s"); // --- TBL: tpl $rslt = updTplTransitAprv($db, $tpl_id, $new_aprv_flg); if (!$rslt) { \Sop\Log::error(__FILE__, __LINE__, 'Failed to update tpl.'); $msg002 = ""; // 登録に失敗しました: transit_aprv \Sop\Api::exitWithError(array($msg002)); } // --- TBL: history $history_id = -1; $rslt = addHistory($db, $history_id, $pj_id, $sop_id, $tpl_id, null, null, null, $HISTORY_ACTION_TPL_TRANSIT, $date, $user_id, null, null); if (!$rslt) { \Sop\Log::error(__FILE__, __LINE__, 'Failed to add history.'); $msg003 = "The registration failed: history"; // 登録に失敗しました: history \Sop\Api::exitWithError(array($msg003)); } // --------------------------- // 終了処理 // --------------------------- $db->commit(); $db = null; $msg004 = "The data was changed to the acceptance available."; // 承認可能にしました $msg005 = "The data was chaged to the acceptance disable."; // 承認申請を取り消しました echo json_encode(array('success' => true, 'msg' => \Sop\Api::htmlEncodeLines(array($new_aprv_flg == 0 ? $msg004 : $msg005)), 'role_aprv' => (bool) $role_aprv, 'role_upld' => (bool) $role_upld)); exit;
} // --- TBL: tpl $revision_no = $ex_latest_tpl_ver + 1; $rslt = updTplAprv($db, $tpl_id, $APRV_FLG_OK, $LATEST_FLG, $aprv_cmnt, $tpl_aprv_date, $user_id, $revision_no); // 承認 if (!$rslt) { \Sop\Log::error(__FILE__, __LINE__, 'Failed to update tpl.'); \Sop\Api::exitWithError(array("更新に失敗しました: tpl")); } // --- TBL: history $history_id = -1; $rslt = addHistory($db, $history_id, $pj_id, $sop_id, $tpl_id, null, null, null, $HISTORY_ACTION_TPL_APRV, $tpl_aprv_date, $user_id, null, $aprv_cmnt); if (!$rslt) { \Sop\Log::error(__FILE__, __LINE__, 'Failed to add history.'); \Sop\Api::exitWithError(array("更新に失敗しました: history")); } if ($ex_latest_tpl_id != null) { $rslt = updTplLatest($db, $ex_latest_tpl_id, $LATEST_FLG_NOT); // 旧最新バージョン tpl の latest_flg を LATEST_FLG_NOT に更新 if (!$rslt) { \Sop\Log::error(__FILE__, __LINE__, 'Failed to update latest_flg.'); \Sop\Api::exitWithError(array("更新に失敗しました: tpl ex-latest")); } } // --------------------------- // 終了処理 // --------------------------- $db->commit(); $db = null; echo json_encode(array('success' => true, 'msg' => \Sop\Api::htmlEncodeLines(array('承認が完了しました')), 'role_aprv' => (bool) $role_aprv, 'role_upld' => (bool) $role_upld)); exit;