Пример #1
0
 public static function setupPDO()
 {
     try {
         $options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8');
         $pdo = new PDO(Config::get('database_dsn'), Config::get('database_user'), Config::get('database_password'), $options);
         $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
         return $pdo;
     } catch (\Exception $e) {
         \Sop\Log::error(__FILE__, __LINE__, 'Failed to setup database connection');
         throw $e;
     }
 }
Пример #2
0
// ---------------------------
$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;
Пример #3
0
<?php

include_once __DIR__ . "/../../sop/src/config.php";
include_once __DIR__ . "/../../sop/src/db_common.php";
\Sop\Database::setupRedBean();
/**
 * ログイン
 */
$user = \Sop\Login::getUser();
// --- ロール判定(管理権限がないとエラー)
if (!$user['admin_flag']) {
    $msg001 = "You do not hava the permission.";
    // 権限がありません
    $message = array($msg001);
    \Sop\Log::warning(__FILE__, __LINE__, 'User (' . $user['user_id'] . ') does not have role.');
    \Sop\Login::exitWithLoginError($message, $message);
}
\Sop\Login::registerToSession($user);
\Sop\Login::exitWithSuccess();
Пример #4
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);
        }
    }
}
Пример #5
0
// ファイル情報取得
// ---------------------------
// --- tpl データ存在チェック
$sel_sql = getSQLBaseForTplList();
$sel_sql .= " AND tpl.tpl_id = :tpl_id";
$sql = "SELECT count(*) cnt FROM ({$sel_sql}) as tmp";
$params = array();
$params[':tpl_id'] = $tpl_id;
$stmt = $db->prepare($sql);
$stmt->execute($params);
$cnt = 0;
foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
    $cnt = (int) $row['cnt'];
}
if ($cnt == 0) {
    \Sop\Log::warning(__FILE__, __LINE__, 'User tries to get non-existent sop.');
    $msg005 = "The object of data already has been deleted.";
    // 対象のデータは既に削除されています
    \Sop\Api::exitWithError(array($msg005));
}
// --- schema 取得
$sql = getSQLBaseForSchemaList();
$sql .= " AND schema.tpl_id = :tpl_id AND v_tpl.grp_id = :grp_id";
$params = array();
$params[':tpl_id'] = $tpl_id;
$params[':grp_id'] = $grp_id;
$stmt = $db->prepare($sql);
$stmt->execute($params);
$schema = null;
foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
    $schema = $row;
Пример #6
0
    if ($div == 'upd') {
        // --- TBL: form
        $rslt = updForm($db, $form_id, $pj_id, $sop_id, $tpl_id, $x, $y, $width, $height, $element_type, $default_value);
        if (!$rslt) {
            \Sop\Log::error(__FILE__, __LINE__, 'Failed to update form.');
            $msg004 = "The update failed.";
            // 更新に失敗しました: form
            \Sop\Api::exitWithError(array($msg004));
        }
    }
}
// --- TBL: history
$history_id = -1;
$rslt = addHistory($db, $history_id, $pj_id, $sop_id, $tpl_id, null, null, null, $HISTORY_ACTION_TPL_FORM_UPSERT, date("Y-m-d H:i:s"), $user_id, null, null);
if (!$rslt) {
    \Sop\Log::error(__FILE__, __LINE__, 'Failed to update form.');
    $msg005 = "The registration and/or update failed.: history";
    // 登録・更新に失敗しました: history
    \Sop\Api::exitWithError(array($msg005));
}
// ---------------------------
// 終了処理
// ---------------------------
$db->commit();
$db = null;
if ($div == 'add') {
    $msg006 = "The registration completed.";
    echo json_encode(array('success' => true, 'msg' => \Sop\Api::htmlEncodeLines(array($msg006))));
    // 登録が完了しました
}
if ($div == 'upd') {
Пример #7
0
    // 削除に失敗しました: clmn
    \Sop\Api::exitWithError(array($msg010));
}
// --- TBL: row
$rslt = delPjRow($db, $pj_id);
if (!$rslt) {
    \Sop\Log::error(__FILE__, __LINE__, 'Failed to delete row.');
    $msg011 = "The delete failed.: row";
    // 削除に失敗しました: row
    \Sop\Api::exitWithError(array(_("削除に失敗しました: row")));
}
// --- TBL: history
$history_id = -1;
$rslt = addHistory($db, $history_id, $pj_id, null, null, null, null, null, $HISTORY_ACTION_PJ_DEL, date("Y-m-d H:i:s"), $user_id, null, null);
if (!$rslt) {
    \Sop\Log::error(__FILE__, __LINE__, 'Failed to delete history.');
    $msg012 = "The delete failed.: history";
    // 削除に失敗しました: history
    \Sop\Api::exitWithError(array($msg012));
}
// ---------------------------
// ファイル削除
// ---------------------------
foreach ($file_path_list as $file_path) {
    if (file_exists($file_path)) {
        unlink($file_path);
    }
}
// ---------------------------
// 終了処理
// ---------------------------
Пример #8
0
}
// --- Wordファイルダウンロード(Wordファイルダウンロード ボタン押下時)
if ($btn == 'src') {
    $sql = getSQLBaseForSchemaList();
    $sql .= " AND schema.tpl_id = :tpl_id AND schema.schema_type = :schema_type";
    $params = array();
    $params[':tpl_id'] = $tpl_id;
    $params[':schema_type'] = $SCHEMA_TYPE_SRC;
    $stmt = $db->prepare($sql);
    $stmt->execute($params);
    $schema = null;
    foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
        $schema = $row;
    }
    if ($schema == null) {
        \Sop\Log::warning(__FILE__, __LINE__, 'Specified schema does not exist.');
        $msg004 = "The data already has been deleted.";
        // 対象のデータは既に削除されています
        \Sop\Api::exitWithError(array($msg004));
    }
    $info = pathinfo($schema['file_path']);
    $extensionList = array('.doc', '.docx');
    foreach ($extensionList as $i) {
        $file_path = str_replace(".{$info['extension']}", $i, $row['file_path']);
        if (file_exists($file_path)) {
            $file_name = $schema['original_filename'] . $i;
            break;
        }
    }
}
// ---------------------------
Пример #9
0
$params = array();
$params[':tpl_id'] = $tpl_id;
$stmt = $db->prepare($sql);
$stmt->execute($params);
$schema_list = array();
foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
    $schema = $row;
    if ($schema['schema_type'] == $SCHEMA_TYPE_SRC) {
        $html = str_replace(array("\r\n", "\r", "\n", "\t"), '', file_get_contents($schema['file_path']));
        $html = \Sop\Form::replaceFormInjectionTag($html, $tpl_id);
        $schema['config'] = $html;
    }
    if ($schema['schema_type'] == $SCHEMA_TYPE_TBL) {
        $schema['config'] = getSchemaVcfgForExt($db, $schema['schema_id']);
    }
    array_push($schema_list, $schema);
}
if (count($schema_list) == 0) {
    \Sop\Log::warning(__FILE__, __LINE__, 'There is not associated schema.');
    $msg002 = "There is not the schema information.";
    // スキーマ情報が存在しません
    \Sop\Api::exitWithError(array($msg002));
}
// ---------------------------
// 終了処理
// ---------------------------
$db = null;
$msg003 = "The system succeeded in an accession to the data.";
// データの取得に成功しました
echo json_encode(array('success' => true, 'msg' => \Sop\Api::htmlEncodeLines(array($msg003)), 'schema_list' => $schema_list));
exit;
Пример #10
0
if ($div == 'add') {
    // --- TBL: grp
    $grp_id = -1;
    $rslt = addGrp($db, $grp_id, $grp_name);
    if (!$rslt) {
        \Sop\Log::error(__FILE__, __LINE__, 'Failed to insert group.');
        $msg002 = "The registration failed.: grp";
        // 登録に失敗しました: grp
        \Sop\Api::exitWithError(array($msg002));
    }
}
if ($div == 'upd') {
    // --- TBL: grp
    $rslt = updGrp($db, $grp_id, $grp_name);
    if (!$rslt) {
        \Sop\Log::error(__FILE__, __LINE__, 'Failed to update group.');
        $msg003 = "The update failed.: grp";
        // 更新に失敗しました: grp
        \Sop\Api::exitWithError(array($msg003));
    }
}
// ---------------------------
// 終了処理
// ---------------------------
$db->commit();
$db = null;
if ($div == 'add') {
    $msg004 = "The registration completed.";
    // 登録が完了しました
    echo json_encode(array('success' => true, 'msg' => \Sop\Api::htmlEncodeLines(array($msg004))));
}
Пример #11
0
    \Sop\Api::exitWithError(array($msg002));
}
// ---------------------------
// データ削除
// ---------------------------
$db->beginTransaction();
// --- TBL: user
$rslt = delUser($db, $user_id);
if (!$rslt) {
    \Sop\Log::error(__FILE__, __LINE__, 'Failed to delete user.');
    $msg003 = "The delete failed.: user";
    // 削除に失敗しました: user
    \Sop\Api::exitWithError(array($msg003));
}
// --- TBL: user_grp
$rslt = delUserGrp($db, $user_id);
if (!$rslt) {
    \Sop\Log::error(__FILE__, __LINE__, 'Failed to delete user_grp.');
    $msg004 = "The delete failed.: user_grp";
    // 削除に失敗しました: user_grp
    \Sop\Api::exitWithError(array($msg004));
}
// ---------------------------
// 終了処理
// ---------------------------
$db->commit();
$db = null;
$msg005 = "The delete completed.";
// 削除が完了しました
echo json_encode(array('success' => true, 'msg' => \Sop\Api::htmlEncodeLines(array($msg005))));
exit;
Пример #12
0
    $history_id = -1;
    $rslt = addHistory($db, $history_id, $pj_id, null, null, null, null, null, $HISTORY_ACTION_PJ_UPD, date("Y-m-d H:i:s"), $user_id, null, null);
    if (!$rslt) {
        unlink($file_path);
        \Sop\Log::error(__FILE__, __LINE__, 'Failed to add history.');
        $msg015 = "The update failed.: history";
        // 更新に失敗しました: history
        \Sop\Api::exitWithError(array($msg015));
    }
}
foreach ($smpl_list as $display_order => $smpl_given_no) {
    // --- TBL: pj_smpl
    $rslt = addPjSmpl($db, $pj_id, $smpl_given_no, $display_order);
    if (!$rslt) {
        unlink($file_path);
        \Sop\Log::error(__FILE__, __LINE__, 'Failed to add pj_smpl.');
        $msg016 = "The update failed.: pj_smpl";
        // 更新に失敗しました: pj_smpl
        \Sop\Api::exitWithError(array($msg016));
        exit;
    }
}
// ---------------------------
// 終了処理
// ---------------------------
$db->commit();
$db = null;
unlink($file_path);
if ($div == 'add') {
    $msg017 = "The registration completed.";
    // 登録が完了しました
Пример #13
0
function sop_exception_handler($exception)
{
    \Sop\Log::error(__FILE__, __LINE__, 'exception ' . $exception->getMessage());
}
Пример #14
0
$cnt = 0;
foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
    $cnt = (int) $row['cnt'];
}
if ($cnt == 0) {
    \Sop\Log::warning(__FILE__, __LINE__, 'User tried to delete non-existent user.');
    $msg002 = "This user already has been deleted.";
    // このユーザーは既に削除されています
    \Sop\Api::exitWithError(array($msg002));
}
// ---------------------------
// データ登録
// ---------------------------
$db->beginTransaction();
// --- TBL: user
$rslt = updPwd($db, $user_id, $password);
if (!$rslt) {
    \Sop\Log::error(__FILE__, __LINE__, 'Failed to update user.');
    $msg003 = "The update failed.: user";
    // 更新に失敗しました: user
    \Sop\Api::exitWithError(array($msg003));
}
// ---------------------------
// 終了処理
// ---------------------------
$db->commit();
$db = null;
$msg004 = "The change completed.";
// 変更が完了しました
echo json_encode(array('success' => true, 'msg' => \Sop\Api::htmlEncodeLines(array($msg004))));
exit;
Пример #15
0
}
// --- 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;
Пример #16
0
    }
    // --- TBL: user_grp
    $rslt = delUserGrp($db, $user_id);
    if (!$rslt) {
        \Sop\Log::error(__FILE__, __LINE__, 'Failed to delete user_grp.');
        $msg010 = "The delete failed.: user_grp";
        // 削除に失敗しました: user_grp
        \Sop\Api::exitWithError(array($msg010));
    }
}
//foreach($grp_id_list as $grp_id)
//{
// --- TBL: user_grp
$rslt = addUserGrp($db, $user_id, $grp_id);
if (!$rslt) {
    \Sop\Log::error(__FILE__, __LINE__, 'Failed to add user_grp.');
    $msg011 = "The registration failed.: grp_id";
    // 登録に失敗しました: grp_id
    \Sop\Api::exitWithError(array($msg011));
}
//}
// ---------------------------
// 終了処理
// ---------------------------
$db->commit();
$db = null;
if ($div == 'add') {
    $msg012 = "The registration completed.";
    // 登録が完了しました
    echo json_encode(array('success' => true, 'msg' => \Sop\Api::htmlEncodeLines(array($msg012))));
}