/** * 最大値のチェックを行う * * @access public * @param string $name フォームの名前 * @param mixed $var フォームの値 * @param array $params プラグインのパラメータ * @return true: 成功 Ethna_Error: エラー */ public function validate($name, $var, $params) { $true = true; $type = $this->getFormType($name); if (isset($params['strmaxcompat']) == false || $this->isEmpty($var, $type)) { return $true; } $ctl = $this->backend->getController(); $client_enc = $ctl->getClientEncoding(); if (mb_enabled() && (strcasecmp('EUC-JP', $client_enc) != 0 && strcasecmp('eucJP-win', $client_enc) != 0)) { $var = mb_convert_encoding($var, 'EUC-JP', $client_enc); } if ($type == VAR_TYPE_STRING) { $max_param = $params['strmaxcompat']; if (strlen($var) > $max_param) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('Please input less than %d full-size (%d half-size) characters to {form}.'); } return Ethna::raiseNotice($msg, E_FORM_MAX_STRING, array(intval($max_param / 2), $max_param)); } } return $true; }
/** * 最小値のチェックを行う * * @access public * @param string $name フォームの名前 * @param mixed $var フォームの値 * @param array $params プラグインのパラメータ */ public function validate($name, $var, $params) { $true = true; $type = $this->getFormType($name); if (isset($params['min']) == false || $this->isEmpty($var, $type)) { return $true; } switch ($type) { case VAR_TYPE_INT: if ($var < $params['min']) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('Please input more than %d(int) to {form}.'); } return Ethna::raiseNotice($msg, E_FORM_MIN_INT, array($params['min'])); } break; case VAR_TYPE_FLOAT: if ($var < $params['min']) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('Please input more than %f(float) to {form}.'); } return Ethna::raiseNotice($msg, E_FORM_MIN_FLOAT, array($params['min'])); } break; case VAR_TYPE_DATETIME: $t_min = strtotime($params['min']); $t_var = strtotime($var); if ($t_var < $t_min) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('Please input datetime value %s or later to {form}.'); } return Ethna::raiseNotice($msg, E_FORM_MIN_DATETIME, array($params['min'])); } break; case VAR_TYPE_FILE: $st = stat($var['tmp_name']); if ($st[7] < $params['min'] * 1024) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('Please specify file whose size is more than %d KB.'); } return Ethna::raiseNotice($msg, E_FORM_MIN_FILE, array($params['min'])); } break; case VAR_TYPE_STRING: $params['mbstrmin'] = $params['min']; unset($params['min']); $vld = $this->plugin->getPlugin('Validator', 'Mbstrmin'); return $vld->validate($name, $var, $params); break; } return $true; }
/** * smarty function:フォームのsubmitボタン生成 * * @param string $submit フォーム項目名 */ function smarty_function_form_submit($params, &$smarty) { $view = Ethna_Container::getInstance()->getView(); if ($view === null) { return null; } //ここでi18n変換をかます $params['value'] = _et($params['value']); return $view->getFormSubmit($params); }
protected function jsonI18n(&$params) { if (!is_array($params)) { $params = _et($params); return true; } else { foreach ($params as $key => $value) { $this->jsonI18n($params[$key]); } } }
/** * フォーム値の型チェックを行う * * @access public * @param string $name フォームの名前 * @param mixed $var フォームの値 * @param array $params プラグインのパラメータ */ public function validate($name, $var, $params) { $true = true; $type = $params['type']; if ($type == VAR_TYPE_FILE || $this->isEmpty($var, $type)) { return $true; } foreach (array_keys(to_array($var)) as $key) { switch ($type) { case VAR_TYPE_INT: if (!preg_match('/^-?\\d+$/', $var)) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('Please input integer value to {form}.'); } return Ethna::raiseNotice($msg, E_FORM_WRONGTYPE_INT); } break; case VAR_TYPE_FLOAT: if (!preg_match('/^-?\\d+$/', $var) && !preg_match('/^-?\\d+\\.\\d+$/', $var)) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('Please input float value to {form}.'); } return Ethna::raiseNotice($msg, E_FORM_WRONGTYPE_FLOAT); } break; case VAR_TYPE_BOOLEAN: if ($var != "1" && $var != "0") { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('You can input 0 or 1 to {form}.'); } return Ethna::raiseNotice($msg, E_FORM_WRONGTYPE_BOOLEAN); } break; case VAR_TYPE_DATETIME: $r = strtotime($var); if ($r == -1 || $r === false) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('Please input valid datetime to {form}.'); } return Ethna::raiseNotice($msg, E_FORM_WRONGTYPE_DATETIME); } break; } } return $true; }
/** * * @see Ethna_ActionClass::perform() */ function perform() { $days = $this->config->get('license_warning_days'); try { $licenseDao = DaoFactory::LicenseMst(); $userDao = DaoFactory::UserMst(); $companyDao = DaoFactory::CompanyMst(); sort($days, SORT_NUMERIC); $result = array(); foreach ($days as $day) { $params = array('day' => $day); $res = $licenseDao->LicenseMST_GetLicenseValidDays($params)->fetchAll(PDO::FETCH_ASSOC); $result = array_merge($result, $res); } foreach ($result as $value) { $send_email[$value['COMPANY_ID']][] = array('TERMINAL_ID' => $value['TERMINAL_ID'], 'END_YMD' => $value['END_YMD']); } //send e-mail $headers = "From: {$this->config->get('admin_email_address')}"; foreach ($send_email as $company => $arr) { $invalid_terminal_list = ''; foreach ($arr as $key => $value) { $invalid_terminal_list .= "\n{$value['TERMINAL_ID']}\t\t\t{$value['END_YMD']}"; } //get admin user's e-mail address and language $companyInfo = $companyDao->Retrieve('COMPANY_ID = ?', array($company)); //$companyInfo['CONTACT'] $userInfo = $userDao->Retrieve("LOGIN_ID = 'admin' AND COMPANY_ID = ? ", array($company)); //$userInfo['E_MAIL'] //$userInfo['DEFAULT_LOCALE'] zh-Hans-CN en_US ja_JP if ($userInfo['DEFAULT_LOCALE'] == 'zh-Hans-CN') { $this->backend->getController()->setLocale('zh-Hans-CN'); $subject = _et($this->config->get('system_name')) . "终端证书即将到期"; $send_message = "\n{$companyInfo['COMPANY_NAME']} \n{$companyInfo['CONTACT']} 您好!\n \t\n非常感谢您使用我们的{$this->config->get('app_name')}服务。\n您的以下终端的证书即将过期,为了不影响业务请尽快到证书管理页面购买新的证书。\n\n终端\t\t\t到期日\n" . $invalid_terminal_list . "\n\n新的证书可以从后台管理系统的证书管理页面购买,也可以直接到AsShop购买。\n如有任何问题请随即和我们取得联系。\n\n服务总站 http://www.asx4.net\nAsWiki\t\thttps://wiki.asx4.net\nAsHelp \thttps://support.asx4.net\nAsShop\thttps://ec.asx4.net\n \t\n"; } elseif ($userInfo['DEFAULT_LOCALE'] == 'ja_JP') { $this->backend->getController()->setLocale('ja_JP'); $subject = _et($this->config->get('system_name')) . "端末のライセンスの期限が近づいています"; $send_message = "\n{$companyInfo['COMPANY_NAME']} \n{$companyInfo['CONTACT']} 様\n \t\n{$this->config->get('app_name')}をご利用いただきまして誠にありがとうございます。\n下記の端末のライセンスの期限が近づいています。業務に影響を与えないように早めに新しいライセンスをご購入ください。\n\n端末ID\t\t\t期限\n" . $invalid_terminal_list . "\n\nライセンスは管理画面のライセンスマスタ画面か、AsShopからご購入いただけます。\nご不明な点がございましたら、お問い合わせください。\n\nサービスホーム http://www.asx4.net\nAsWiki \t\t\t\thttps://wiki.asx4.net\nAsHelp \t\t\t\thttps://support.asx4.net\nAsShop \t\t\t\thttps://ec.asx4.net \n \t\n"; } else { $this->backend->getController()->setLocale('en_US'); $subject = _et($this->config->get('system_name')) . " Terminal will be out of license soon"; $send_message = "\n{$companyInfo['COMPANY_NAME']} \nHi {$companyInfo['CONTACT']}\n \t\nThanks for using our {$this->config->get('app_name')} service. \nThe following terminal will be out of license soon. Please buy new license as soon as possible.\n\nTerminal ID\t\t\tValid Until\n" . $invalid_terminal_list . "\n\nYou can buy new licenses from the LICENSE MANAGEMENT page in our admin system or buy form the AsShop directly.\nIf you have any question, please don't hesitate to contact us.\n\nService Home\t\thttp://www.asx4.net\nAsWiki \t\t\thttps://wiki.asx4.net\nAsHelp \t\t\thttps://support.asx4.net\nAsShop \t\t\thttps://ec.asx4.net\n"; } mb_send_mail($userInfo['E_MAIL'], $subject, $send_message, $headers); } } catch (Exception $e) { $this->logger->log(LOG_ERR, $e->getMessage()); die($e->getMessage()); } }
/** * 正規表現によるフォーム値のチェックを行う * * @access public * @param string $name フォームの名前 * @param mixed $var フォームの値 * @param array $params プラグインのパラメータ */ function &validate($name, $var, $params) { $true = true; $type = $this->getFormType($name); if (isset($params['regexp']) == false || $type == VAR_TYPE_FILE || $this->isEmpty($var, $type)) { return $true; } if (preg_match($params['regexp'], $var) == 0) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('Please input {form} properly.'); } return Ethna::raiseNotice($msg, E_FORM_REGEXP); } return $true; }
/** * 最小値のチェックを行う (シングルバイト文字列用) * * @access public * @param string $name フォームの名前 * @param mixed $var フォームの値 * @param array $params プラグインのパラメータ */ function &validate($name, $var, $params) { $true = true; $type = $this->getFormType($name); if (isset($params['strmin']) == false || $this->isEmpty($var, $type)) { return $true; } if ($type == VAR_TYPE_STRING) { $min_param = $params['strmin']; if (strlen($var) < $min_param) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('Please input more than %d characters to {form}.'); } return Ethna::raiseNotice($msg, E_FORM_MIN_STRING, array($min_param)); } } return $true; }
/** * 正規表現によるフォーム値のチェックを行う(マルチバイト対応) * * @access public * @param string $name フォームの名前 * @param mixed $var フォームの値 * @param array $params プラグインのパラメータ */ public function validate($name, $var, $params) { $true = true; $type = $this->getFormType($name); if (isset($params['mbregexp']) == false || $type == VAR_TYPE_FILE || $this->isEmpty($var, $type)) { return $true; } $ctl = $this->backend->getController(); $cli_enc = $ctl->getClientEncoding(); $encoding = isset($params['encoding']) ? $params['encoding'] : $cli_enc; mb_regex_encoding($encoding); if (mb_ereg($params['mbregexp'], $var) !== 1) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('Please input {form} properly.'); } return Ethna::raiseNotice($msg, E_FORM_REGEXP); } return $true; }
/** * メールを送信する * * $attach の指定方法: * - 既存のファイルを添付するとき * <code> * array('filename' => '/tmp/hoge.xls', 'content-type' => 'application/vnd.ms-excel') * </code> * - 文字列に名前を付けて添付するとき * <code> * array('name' => 'foo.txt', 'content' => 'this is foo.') * </code> * 'content-type' 省略時は 'application/octet-stream' となる。 * 複数添付するときは上の配列を添字0から始まるふつうの配列に入れる。 * * @access public * @param string $to メール送信先アドレス (nullのときは送信せずに内容を return する) * @param string $template メールテンプレート名 or タイプ * @param array $macro テンプレートマクロ or $templateがMAILSENDER_TYPE_DIRECTのときはメール送信内容) * @param array $attach 添付ファイル */ function send($to, $template, $macro, $attach = null) { // メール内容を作成 if ($template === MAILSENDER_TYPE_DIRECT) { $mail = $macro; } else { $renderer = $this->getTemplateEngine(); // 基本情報設定 $env_datetime = _et('%Y/%m/%d %H:%M:%S'); $renderer->setProp("env_datetime", strftime($env_datetime)); $renderer->setProp("env_useragent", $_SERVER["HTTP_USER_AGENT"]); $renderer->setProp("env_remoteaddr", $_SERVER["REMOTE_ADDR"]); // デフォルトマクロ設定 $macro = $this->_setDefaultMacro($macro); // ユーザ定義情報設定 if (is_array($macro)) { foreach ($macro as $key => $value) { $renderer->setProp($key, $value); } } if (isset($this->def[$template])) { $template = $this->def[$template]; } $mail = $renderer->perform(sprintf('%s/%s', $this->mail_dir, $template), true); if (Ethna::isError($mail)) { return $mail; } } if ($to === null) { return $mail; } // メール内容をヘッダと本文に分離 $mail = str_replace("\r\n", "\n", $mail); list($header, $body) = $this->_parse($mail); // 添付ファイル (multipart) if ($attach !== null) { $attach = isset($attach[0]) ? $attach : array($attach); $boundary = Ethna_Util::getRandom(); $body = "This is a multi-part message in MIME format.\n\n" . "--{$boundary}\n" . "Content-Type: text/plain; charset=utf-8\n" . "Content-Transfer-Encoding: 8bit\n\n" . "{$body}\n"; foreach ($attach as $part) { if (isset($part['content']) === false && isset($part['filename']) && is_readable($part['filename'])) { $part['content'] = file_get_contents($part['filename']); $part['filename'] = basename($part['filename']); } if (isset($part['content']) === false) { continue; } if (isset($part['content-type']) === false) { $part['content-type'] = 'application/octet-stream'; } if (isset($part['name']) === false) { $part['name'] = $part['filename']; } if (isset($part['filename']) === false) { $part['filename'] = $part['name']; } $part['name'] = preg_replace_callback('/([^\\x00-\\x7f]+)/', function ($matches) { return Ethna_Util::encode_MIME($matches[1]); }, $part['name']); // XXX: rfc2231 $part['filename'] = preg_replace_callback('/([^\\x00-\\x7f]+)/', function ($matches) { return Ethna_Util::encode_MIME($matches[1]); }, $part['filename']); $body .= "--{$boundary}\n" . "Content-Type: " . $part['content-type'] . ";\n" . "\tname=\"" . $part['name'] . "\"\n" . "Content-Transfer-Encoding: base64\n" . "Content-Disposition: attachment;\n" . "\tfilename=\"" . $part['filename'] . "\"\n\n"; $body .= chunk_split(base64_encode($part['content'])); } $body .= "--{$boundary}--"; } // ヘッダ if (isset($header['mime-version']) === false) { $header['mime-version'] = array('Mime-Version', '1.0'); } if (isset($header['subject']) === false) { $header['subject'] = array('Subject', 'no subject in original'); } if (isset($header['content-type']) === false) { $header['content-type'] = array('Content-Type', $attach === null ? 'text/plain; charset=utf-8' : "multipart/mixed; \n\tboundary=\"{$boundary}\""); } if (isset($header['content-transfer-encoding']) === false) { $header['Content-Transfer-Encoding'] = ['Content-Transfer-Encoding', '8bit']; } $header_line = ""; foreach ($header as $key => $value) { if ($key == 'subject') { // should be added by mail() continue; } if ($header_line != "") { $header_line .= "\n"; } $header_line .= $value[0] . ": " . $value[1]; } // 改行コードを CRLF に if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { $body = str_replace("\n", "\r\n", $body); } $wa_config = 'mail_func_workaround'; if ($this->config->get($wa_config) == false && isset($this->options[$wa_config]) == false) { $header_line = str_replace("\n", "\r\n", $header_line); } // 送信 foreach (to_array($to) as $rcpt) { if (is_string($this->option)) { mail($rcpt, $header['subject'][1], $body, $header_line, $this->option); } else { mail($rcpt, $header['subject'][1], $body, $header_line); } } }
/** * Ethnaの設定一覧を取得する * * @access public * @return array 設定一覧を格納した配列 * @todo respect access controll */ function getConfiguration() { $r = array(); // core $elts = array(); $elts[_et('Application ID')] = $this->ctl->getAppId(); $elts[_et('Application URL')] = $this->ctl->getURL(); $elts[_et('Ethna Version')] = ETHNA_VERSION; $elts[_et('Ethna Base Directory')] = ETHNA_BASE; $r['Core'] = $elts; // class $elts = array(); $elts[_et('Backend')] = $this->class_factory->getObjectName('backend'); $elts[_et('ClassFactory')] = $this->class_factory->getObjectName('class'); $elts[_et('Config')] = $this->class_factory->getObjectName('config'); $elts['DB'] = $this->class_factory->getObjectName('db'); $elts[_et('Error')] = $this->class_factory->getObjectName('error'); $elts[_et('Form')] = $this->class_factory->getObjectName('form'); $elts[_et('Log')] = $this->class_factory->getObjectName('logger'); $elts['i18n'] = $this->class_factory->getObjectName('i18n'); $elts[_et('Plugin')] = $this->class_factory->getObjectName('plugin'); $elts[_et('Session')] = $this->class_factory->getObjectName('session'); $elts['SQL'] = $this->class_factory->getObjectName('sql'); $elts[_et('View')] = $this->class_factory->getObjectName('view'); $r[_et('Class')] = $elts; // DB $elts = array(); $db_list = array(); foreach ($dbl = $this->_getInvisibleProperty($this->ctl, 'db') as $key => $db) { if ($key == "") { $tmp = '$db'; } else { $tmp = sprintf('$db_%s', $key); } $elts[$tmp] = $this->getAttrName('db_type', $db); $db_list[$key] = $tmp; } $r[_et('DB Type')] = $elts; // DSN $elts = array(); foreach ($db_list as $key => $name) { $config_key = "dsn"; if ($key != "") { $config_key .= "_{$key}"; } $dsn = $this->config->get($config_key); if ($dsn) { $elts[$name] = implode("\n", to_array($dsn)); } } $r['DSN'] = $elts; // directory $elts = array(); $elts[_et('Application')] = $this->ctl->getBasedir(); $elts[_et('Action')] = $this->ctl->getActiondir(); $elts[_et('View')] = $this->ctl->getViewdir(); $elts[_et('Filter')] = $this->ctl->getDirectory('filter'); $elts[_et('Plugin')] = $this->ctl->getDirectory('plugin'); $elts[_et('Template')] = $this->ctl->getTemplatedir(); $elts[_et('Template Cache')] = $this->ctl->getDirectory('template_c'); $elts[_et('Smarty Plugin')] = implode(',', $this->ctl->getDirectory('plugins')); $elts[_et('Configuration File')] = $this->ctl->getDirectory('etc'); $elts[_et('Locale')] = $this->ctl->getDirectory('locale'); $elts[_et('Logging')] = $this->ctl->getDirectory('log'); $elts[_et('Temporary File')] = $this->ctl->getDirectory('tmp'); $r[_et('Directory')] = $elts; // ext $elts = array(); $elts[_et('Template')] = $this->ctl->getExt('tpl'); $elts[_et('PHP Script')] = $this->ctl->getExt('php'); $r[_et('File Extention')] = $elts; // filter $elts = array(); $n = 1; foreach ($this->_getInvisibleProperty($this->ctl, 'filter') as $filter) { $key = sprintf(_et('Filter(%d)'), $n); if (class_exists($filter)) { $elts[$key] = $filter; $n++; } } $r[_et('Filter')] = $elts; // manager $elts = array(); foreach ($this->ctl->getManagerList() as $key => $manager) { $name = sprintf('$%s', $key); $elts[$name] = $this->ctl->getManagerClassName($manager); } $r[_et('Application Manager')] = $elts; return $r; }
/** * 最小値のチェックを行う * * @access public * @param string $name フォームの名前 * @param mixed $var フォームの値 * @param array $params プラグインのパラメータ */ function validate($name, $var, $params) { $true = true; $type = $this->getFormType($name); if (isset($params['min']) == false || $this->isEmpty($var, $type)) { return $true; } switch ($type) { case VAR_TYPE_INT: if ($var < $params['min']) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('Please input more than %d(int) to {form}.'); } return Ethna::raiseNotice($msg, E_FORM_MIN_INT, array($params['min'])); } break; case VAR_TYPE_FLOAT: if ($var < $params['min']) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('Please input more than %f(float) to {form}.'); } return Ethna::raiseNotice($msg, E_FORM_MIN_FLOAT, array($params['min'])); } break; case VAR_TYPE_DATETIME: $t_min = strtotime($params['min']); $t_var = strtotime($var); if ($t_var < $t_min) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('Please input datetime value %s or later to {form}.'); } return Ethna::raiseNotice($msg, E_FORM_MIN_DATETIME, array($params['min'])); } break; case VAR_TYPE_FILE: $st = stat($var['tmp_name']); if ($st[7] < $params['min'] * 1024) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('Please specify file whose size is more than %d KB.'); } return Ethna::raiseNotice($msg, E_FORM_MIN_FILE, array($params['min'])); } break; case VAR_TYPE_STRING: // // マルチバイトエンコーディングと、そうでない場合で // 異なるプラグインを呼ぶ。 // // これは Ethna_Controller#client_encoding の値によ // って動きが決まる // $ctl = Ethna_Controller::getInstance(); $client_enc = $ctl->getClientEncoding(); $plugin = $this->backend->getPlugin(); // select Plugin. if (mb_enabled() && strcasecmp('UTF-8', $client_enc) == 0) { $plugin_name = 'Mbstrmin'; $params['mbstrmin'] = $params['min']; } elseif (strcasecmp('EUC-JP', $client_enc == 0) || strcasecmp('eucJP-win', $client_enc == 0)) { $plugin_name = 'Strmincompat'; $params['strmincompat'] = $params['min']; } else { $plugin_name = 'Strmin'; $params['strmin'] = $params['min']; } unset($params['min']); $vld = $plugin->getPlugin('Validator', $plugin_name); return $vld->validate($name, $var, $params); break; } return $true; }
/** * 元号制での年を返す * * @access public * @param int $t unix time * @return string 元号(不明な場合はnull) */ public static function getEra($t) { $tm = localtime($t, true); $year = $tm['tm_year'] + 1900; if ($year >= 1989) { $heisei_str = _et('Heisei'); return array($heisei_str, $year - 1988); } else { if ($year >= 1926) { $showa_str = _et('Showa'); return array($showa_str, $year - 1925); } } return null; }
/** * フォームタグを取得する(type="submit") * * @access protected */ function _getFormInput_Submit($name, $def, $params) { $params['type'] = 'submit'; if (isset($def['type'])) { $params['name'] = is_array($def['type']) ? $name . '[]' : $name; } else { $params['name'] = $name; } if (isset($params['value']) === false) { if (isset($def['name'])) { $params['value'] = _et($def['name']); } } if (is_array($params['value'])) { $params['value'] = $params['value'][0]; } return $this->_getFormInput_Html('input', $params); }
/** * アップロードされたファイルのチェックを行う * XXX: プラグインのエラーコードを修正する * * @access public * @param string $name フォームの名前 * @param mixed $var フォームの値 * @param array $params プラグインのパラメータ */ function &validate($name, $var, $params) { $true = true; if ($this->getFormType($name) != VAR_TYPE_FILE) { return $true; } // そもそもアップロードされていない場合はスキップ if ($var['error'] == UPLOAD_ERR_NO_FILE) { return $true; } // エラーコードの検査 $msg = ''; switch ($var['error']) { case UPLOAD_ERR_INI_SIZE: $msg = _et("Uploaded file size exceeds php.ini's upload_max_filesize directive."); break; case UPLOAD_ERR_FORM_SIZE: $msg = _et('Uploaded File size exceeds MAX_FILE_SIZE specified in HTML Form.'); break; case UPLOAD_ERR_PARTIAL: $msg = _et('File was only uploaded patially.'); break; case UPLOAD_ERR_NO_FILE: $msg = _et('File was not uploaded.'); break; case UPLOAD_ERR_NO_TMP_DIR: $msg = _et('Temporary folder was not found.'); break; case UPLOAD_ERR_CANT_WRITE: $msg = _et('Could not write uploaded file to disk.'); break; } if ($msg != '') { if (isset($params['error'])) { $msg = $params['error']; } return Ethna::raiseNotice($msg, E_FORM_WRONGTYPE_FILE); } // tmp_name の検査 if (isset($var['tmp_name']) == false || is_uploaded_file($var['tmp_name']) == false) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('invalid tmp_name.'); } return Ethna::raiseNotice($msg, E_FORM_WRONGTYPE_FILE); } // size の検査 if (isset($params['size_max'])) { $st = stat($var['tmp_name']); if ($st[7] > $this->_getSizeAsBytes($params['size_max'])) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('Uploaded file size must be less than %s.'); } return Ethna::raiseNotice($msg, E_FORM_WRONGTYPE_FILE, array($params['size_max'])); } } if (isset($params['size_min'])) { $st = stat($var['tmp_name']); if ($st[7] < $this->_getSizeAsBytes($params['size_min'])) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('Uploaded file size must be more than %s.'); } return Ethna::raiseNotice($msg, E_FORM_WRONGTYPE_FILE, array($params['size_min'])); } } // type の検査 if (isset($params['type'])) { $type_list = to_array($params['type']); $posted_mime = explode('/', $var['type'], 2); foreach ($type_list as $type) { $wanted_mime = explode('/', $type, 2); $test = count($wanted_mime) == 1 ? strcasecmp($wanted_mime[0], $posted_mime[0]) == 0 : strcasecmp($type, $var['type']) == 0; if ($test == true) { break; } } if ($test == false) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('Invalid file type.'); } return Ethna::raiseNotice($msg, E_FORM_WRONGTYPE_FILE); } } // name(ファイル名)の検査 if (isset($params['name'])) { $test = $params['name'][0] == '/' ? preg_match($params['name'], $var['name']) : strcmp($params['name'], $var['name']) == 0; if ($test == false) { if (isset($params['error'])) { $msg = $params['error']; } else { $msg = _et('Invalid file name.'); } return Ethna::raiseNotice($msg, E_FORM_WRONGTYPE_FILE); } } return $true; }
/** * アプリケーションエラーメッセージを取得する * * @param array エラーエントリ * @return string エラーメッセージ */ protected function getMessageByEntry(&$error) { $form_name = $this->action_form->getName($error['name']); return str_replace("{form}", _et($form_name), $error['object']->getMessage()); }
/** * フォーム値検証のエラー処理を行う * * @access public * @param string $name フォーム項目名 * @param int $code エラーコード */ public function handleError($name, $code) { $def = $this->getDef($name); // ユーザ定義エラーメッセージ $code_map = array(E_FORM_REQUIRED => 'required_error', E_FORM_WRONGTYPE_SCALAR => 'type_error', E_FORM_WRONGTYPE_ARRAY => 'type_error', E_FORM_WRONGTYPE_INT => 'type_error', E_FORM_WRONGTYPE_FLOAT => 'type_error', E_FORM_WRONGTYPE_DATETIME => 'type_error', E_FORM_WRONGTYPE_BOOLEAN => 'type_error', E_FORM_MIN_INT => 'min_error', E_FORM_MIN_FLOAT => 'min_error', E_FORM_MIN_DATETIME => 'min_error', E_FORM_MIN_FILE => 'min_error', E_FORM_MIN_STRING => 'min_error', E_FORM_MAX_INT => 'max_error', E_FORM_MAX_FLOAT => 'max_error', E_FORM_MAX_DATETIME => 'max_error', E_FORM_MAX_FILE => 'max_error', E_FORM_MAX_STRING => 'max_error', E_FORM_REGEXP => 'regexp_error'); // フォーム定義にエラーメッセージが定義されていれば // それを使う if (array_key_exists($code_map[$code], $def)) { $this->ae->add($name, $def[$code_map[$code]], $code); return; } // 定義されていない場合は、内部のメッセージを使う if ($code == E_FORM_REQUIRED) { switch ($def['form_type']) { case FORM_TYPE_TEXT: case FORM_TYPE_PASSWORD: case FORM_TYPE_TEXTAREA: case FORM_TYPE_SUBMIT: $message = _et('Please input {form}.'); break; case FORM_TYPE_SELECT: case FORM_TYPE_RADIO: case FORM_TYPE_CHECKBOX: case FORM_TYPE_FILE: $message = _et('Please select {form}.'); break; default: $message = _et('Please input {form}.'); break; } } else { if ($code == E_FORM_WRONGTYPE_SCALAR) { $message = _et('Please input scalar value to {form}.'); } else { if ($code == E_FORM_WRONGTYPE_ARRAY) { $message = _et('Please input array value to {form}.'); } else { if ($code == E_FORM_WRONGTYPE_INT) { $message = _et('Please input integer value to {form}.'); } else { if ($code == E_FORM_WRONGTYPE_FLOAT) { $message = _et('Please input float value to {form}.'); } else { if ($code == E_FORM_WRONGTYPE_DATETIME) { $message = _et('Please input valid datetime to {form}.'); } else { if ($code == E_FORM_WRONGTYPE_BOOLEAN) { $message = _et('You can input 0 or 1 to {form}.'); } else { if ($code == E_FORM_MIN_INT) { $this->ae->add($name, _et('Please input more than %d(int) to {form}.'), $code, $def['min']); return; } else { if ($code == E_FORM_MIN_FLOAT) { $this->ae->add($name, _et('Please input more than %f(float) to {form}.'), $code, $def['min']); return; } else { if ($code == E_FORM_MIN_DATETIME) { $this->ae->add($name, _et('Please input datetime value %s or later to {form}.'), $code, $def['min']); return; } else { if ($code == E_FORM_MIN_FILE) { $this->ae->add($name, _et('Please specify file whose size is more than %d KB.'), $code, $def['min']); return; } else { if ($code == E_FORM_MIN_STRING) { $this->ae->add($name, _et('Please input more than %d full-size (%d half-size) characters to {form}.'), $code, intval($def['min'] / 2), $def['min']); return; } else { if ($code == E_FORM_MAX_INT) { $this->ae->add($name, _et('Please input less than %d(int) to {form}.'), $code, $def['max']); return; } else { if ($code == E_FORM_MAX_FLOAT) { $this->ae->add($name, _et('Please input less than %f(float) to {form}.'), $code, $def['max']); return; } else { if ($code == E_FORM_MAX_DATETIME) { $this->ae->add($name, _et('Please input datetime value before %s to {form}.'), $code, $def['max']); return; } else { if ($code == E_FORM_MAX_FILE) { $this->ae->add($name, _et('Please specify file whose size is less than %d KB to {form}.'), $code, $def['max']); return; } else { if ($code == E_FORM_MAX_STRING) { $this->ae->add($name, _et('Please input less than %d full-size (%d half-size) characters to {form}.'), $code, intval($def['max'] / 2), $def['max']); return; } else { if ($code == E_FORM_REGEXP) { $message = _et('Please input {form} properly.'); } } } } } } } } } } } } } } } } } } $this->ae->add($name, $message, $code); }
/** * フォームに値が入力されているかを検証する * * 配列の場合は、入力されるべき key のリスト、 * あるいは key の数を指定できます * * @access public * @param string $name フォームの名前 * @param mixed $var フォームの値 * @param array $params プラグインのパラメータ */ function validate($name, $var, $params) { $true = true; if (isset($params['required']) && $params['required'] == false) { return $true; } $form_def = $this->getFormDef($name); // 選択型のフォームかどうか switch ($form_def['form_type']) { case FORM_TYPE_SELECT: case FORM_TYPE_RADIO: case FORM_TYPE_CHECKBOX: case FORM_TYPE_FILE: $choice = true; break; default: $choice = false; } // スカラーの場合 if (is_array($form_def['type']) == false) { if ($this->isEmpty($var, $this->getFormType($name))) { if (isset($params['error'])) { $msg = $params['error']; } else { if ($choice) { $msg = _et('{form} was not selected.'); } else { $msg = _et('no input to {form}.'); } } return Ethna::raiseNotice($msg, E_FORM_REQUIRED); } else { return $true; } } // 配列の場合 $valid_keys = array(); if ($var != null) { foreach (array_keys($var) as $key) { if ($this->isEmpty($var[$key], $this->getFormType($name)) == false) { $valid_keys[] = $key; } } } // 配列の required_key のチェック // 'required_key' => array(xx) に設定された配列の要素値がなければエラー。 if (isset($params['key'])) { $invalid_keys = array_diff(to_array($params['key']), $valid_keys); if (count($invalid_keys) > 0) { if (isset($params['error'])) { $msg = $params['error']; } else { if ($choice) { $msg = _et('Required item of {form} was not selected.'); } else { $msg = _et('Required item of {form} was not submitted.'); } } return Ethna::raiseNotice($msg, E_FORM_REQUIRED); } } // 配列の required_num のチェック // 'required_num' => xx に設定された数より、validな値の数が少なければエラー。 if (isset($params['num'])) { if (count($valid_keys) < intval($params['num'])) { if (isset($params['error'])) { $msg = $params['error']; } else { if ($choice) { $msg = _et('Required numbers of {form} was not selected.'); } else { $msg = _et('Required numbers of {form} was not submitted.'); } } return Ethna::raiseNotice($msg, E_FORM_REQUIRED); } } // とくに指定がないとき: フォームに与えられた全要素に // valid な値が入っていなければならない if (isset($params['key']) == false && isset($params['num']) == false) { if (count($valid_keys) == 0 || count($valid_keys) != count($var)) { if (isset($params['error'])) { $msg = $params['error']; } else { if ($choice) { $msg = _et('Please select {form}.'); } else { $msg = _et('Please input {form}.'); } } return Ethna::raiseNotice($msg, E_FORM_REQUIRED); } } return $true; }