Example #1
0
 $sql = "SELECT count(*) cnt FROM ({$sel_sql}) as tmp";
 $params = array();
 $params[':file_id'] = $file_id;
 $params[':request_time'] = $request_time;
 $params[':seq_no'] = $seq_no;
 $stmt = $db->prepare($sql);
 $stmt->execute($params);
 $cnt = 0;
 foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
     $cnt = (int) $row['cnt'];
 }
 // flie テーブルにレコードがある場合は、リクエストが古いので破棄する。
 if ($cnt != 0) {
     $db->beginTransaction();
     // 過去のリクエストでも、フォームごとの最終時刻がない、もしくは古い場合は更新する。
     $sel_sql = getSQLBaseForValList();
     $sel_sql .= " AND val_name = :val_name AND (update_time < :update_time OR update_time IS NULL)";
     $sql = "SELECT count(*) cnt FROM ({$sel_sql}) as tmp";
     $params = array();
     $params[':file_id'] = $file_id;
     $params[':val_name'] = $target_val_name;
     $params[':update_time'] = $update_time;
     $stmt = $db->prepare($sql);
     $stmt->execute($params);
     $cnt = 0;
     foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
         $cnt = (int) $row['cnt'];
     }
     if ($cnt > 0) {
         // --- フォームの最終更新日時の更新。
         $rslt = updValLastUpdateTime($db, $file_id, $target_val_name, $update_time);
Example #2
0
function getSchemaHtmlForPdf($db, $schema_id, $div, $file_id)
{
    $html = "";
    $html .= "<html><head></head><body>";
    // tbl (sheet)
    $tbl_sql = getSQLBaseForTblList() . " AND tbl.schema_id = :schema_id ORDER BY tbl.tbl_id";
    $stmt = $db->prepare($tbl_sql);
    $stmt->execute(array(':schema_id' => $schema_id));
    foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $tbl) {
        $tbl_id = $tbl['tbl_id'];
        $tbl_title = $tbl['tbl_title'];
        $tbl_html = "";
        $tbl_html .= "<p>{$tbl_title}</p>";
        $tbl_html .= "<table border=\"1\" width='100%'>";
        // ヘッダー行
        $tr_html = "";
        $tr_html .= "<tr>";
        $clmn_sql = getSQLBaseForClmnList() . " AND clmn.tbl_id = :tbl_id ORDER BY clmn.clmn_id";
        $stmt = $db->prepare($clmn_sql);
        $stmt->execute(array(':tbl_id' => $tbl_id));
        foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $idx => $clmn) {
            $clmn_name = $clmn['clmn_name'];
            $tr_html .= "<td bgcolor=\"#c1ddf1\">{$clmn_name}</td>";
        }
        $tr_html .= "</tr>";
        $tbl_html .= $tr_html;
        // データ行
        $clmn_cnt = $idx + 1;
        $row_sql = getSQLBaseForRowList() . " AND row.tbl_id = :tbl_id ORDER BY row.row_order, row.clmn_id";
        $stmt = $db->prepare($row_sql);
        $stmt->execute(array(':tbl_id' => $tbl_id));
        foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $idx => $row) {
            if ($idx % $clmn_cnt == 0) {
                if ($idx != 0) {
                    // 2行目以降
                    $tr_html .= "</tr>";
                    $tbl_html .= $tr_html;
                }
                // 次行の処理に移る
                $tr_html = "";
                $tr_html .= "<tr>";
            }
            $tbl_id = $row['tbl_id'];
            $clmn_id = $row['clmn_id'];
            $row_id = $row['row_id'];
            $input_type = $row['input_type'];
            $input_required = $row['input_required'];
            $row_text = $row['row_text'];
            if ($row_text == '') {
                $xtype = $input_type;
                $item_id = "input_{$tbl_id}_{$clmn_id}_{$row_id}";
                if ($div == 'add') {
                    // add の場合は空欄
                    $tr_html .= "<td>&nbsp;</td>";
                } else {
                    // upd or fix の場合はvalueをセット
                    $val_sql = getSQLBaseForValList() . " AND val.file_id = :file_id AND val.val_name = :val_name";
                    $stmt = $db->prepare($val_sql);
                    $stmt->execute(array(':file_id' => $file_id, ':val_name' => $item_id));
                    $td_html = "<td>&nbsp;</td>";
                    foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $val) {
                        $value = $val['value'];
                        if ($xtype == 'checkboxfield') {
                            $td_html = $value == 'on' ? "<td>○</td>" : "<td>&nbsp;</td>";
                        } else {
                            $td_html = "<td>{$value}</td>";
                        }
                    }
                    $tr_html .= $td_html;
                }
            } else {
                $tr_html .= "<td>{$row_text}</td>";
            }
        }
        $tr_html .= "</tr>";
        $tbl_html .= $tr_html;
        $tbl_html .= "</table><br/>";
        $html .= $tbl_html;
    }
    $html .= "</body></html>";
    return $html;
}
Example #3
0
 /**
  * 手順書のHTMLに入力フォームを注入する。
  *
  * @param string $html HTML
  * @param int    $tpl_id tpl_id
  * @param int    $file_id ユーザー入力値を設定したい場合に指定する。nullの場合、初期値は空になる。
  * @param int    $replace_special {%name%}などを置換するかどうか
  */
 public static function replaceFormInjectionTag($html, $tpl_id, $file_id = null, $replace_special = false)
 {
     // ----------------------------------------
     // 入力欄とデフォルト値の取得
     $sql = getSQLBaseForFormList();
     $sql .= " AND form.tpl_id = :tpl_id";
     $form_list = R::getAll($sql, array(':tpl_id' => $tpl_id));
     // 初期値の設定
     $initial_values = array();
     $vals = array();
     if ($file_id !== null) {
         $sql = getSQLBaseForValList();
         $vals = R::getAll($sql, array('file_id' => $file_id));
     }
     if (empty($vals)) {
         // 入力値が無い場合はデフォルト値を使用
         foreach ($form_list as $form) {
             $name = 'input_' . intval($form['form_id']);
             $value = $form['default_value'];
             if ($replace_special) {
                 // デフォルト値の場合、{%name%}などを置換する
                 $value = str_replace('{%name%}', Session::getSiteData('user_name'), $value);
                 $value = str_replace('{%group%}', Session::getSiteData('grp_name'), $value);
                 $value = str_replace('{%mail%}', Session::getSiteData('email'), $value);
             }
             $initial_values[$name] = $value;
         }
     } else {
         foreach ($vals as $v) {
             $initial_values[$v['val_name']] = $v['value'];
         }
     }
     // ----------------------------------------
     // 入力欄の追加
     $formhtml = '';
     foreach ($form_list as $form) {
         $top = intval($form['y']);
         $left = intval($form['x']);
         $width = intval($form['width']);
         $height = intval($form['height']);
         $name = 'input_' . intval($form['form_id']);
         $formhtml .= '<div' . '  class="injected-input"' . '  style="z-index:999; display:none; position:absolute; top:0; left:0"' . '  data-original-top="' . $top . '"' . '  data-original-left="' . $left . '"' . '  >';
         switch ($form['type']) {
             case 'textbox':
                 if ($height > 80) {
                     $formhtml .= '<textarea' . '  class="injected-input-resizable autosave"' . '  style="font-size: 14px; outline: 3px solid #FA9500;"' . '  name="' . $name . '"' . '  data-original-width="' . $width . '"' . '  data-original-height="' . $height . '"' . '  />';
                     if (isset($initial_values[$name])) {
                         $formhtml .= htmlspecialchars($initial_values[$name]);
                     }
                     $formhtml .= '</textarea>';
                 } else {
                     $formhtml .= '<input' . '  class="injected-input-resizable autosave"' . '  style="font-size: 14px; outline: 3px solid #FA9500;"' . '  name="' . $name . '"' . '  value="' . (isset($initial_values[$name]) ? htmlspecialchars($initial_values[$name]) : '') . '"' . '  data-original-width="' . $width . '"' . '  data-original-height="' . $height . '"' . '  />';
                 }
                 break;
             case 'checkbox':
                 $formhtml .= '<input type="hidden"   name="' . $name . '" value="off" />';
                 $formhtml .= '<input' . '  type="checkbox"' . '  class="autosave"' . '  name="' . $name . '"' . '  value="on"' . (isset($initial_values[$name]) && $initial_values[$name] == 'on' ? 'checked="checked"' : '') . '  data-original-width="' . $width . '"' . '  data-original-height="' . $height . '"' . '  style="outline: 3px solid #FA9500;"' . '  />';
                 break;
         }
         $formhtml .= '</div>';
     }
     return str_replace(Constant::FORM_INJECTION_TAG, $formhtml, $html);
 }