Example #1
0
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);
        }
    }
}
Example #2
0
 }
 // --- TBL: val
 foreach ($_REQUEST as $val_name => $value) {
     if (strpos($val_name, 'input_') !== false) {
         $value = urldecode($value);
         $rslt = updVal($db, $file_id, $val_name, $value);
         if (!$rslt) {
             \Sop\Log::error(__FILE__, __LINE__, 'Failed to update val.');
             $msg007 = "The update failed.: val";
             // 更新に失敗しました: val
             \Sop\Api::exitWithError(array("{$msg007} {$value} (: {$val_name})"));
         }
     }
 }
 // --- TBL: hwr
 $rslt = updHwr($db, $hwr_id, $hwr_val);
 if (!$rslt) {
     \Sop\Log::error(__FILE__, __LINE__, 'Failed to update hwr.');
     $msg008 = "The update failed.: hwr";
     // 更新に失敗しました: hwr
     \Sop\Api::exitWithError(array($msg008));
 }
 // --- TBL: history
 $history_id = -1;
 $rslt = addHistory($db, $history_id, $pj_id, $sop_id, $tpl_id, $schema_id, $file_id, $smpl_given_no, $HISTORY_ACTION_FILE_UPD, $date, $user_id, $user_id_2, null);
 if (!$rslt) {
     \Sop\Log::error(__FILE__, __LINE__, 'Failed to update history.');
     $msg009 = "The update failed.: history";
     // 更新に失敗しました: history
     \Sop\Api::exitWithError(array($msg009));
 }