| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved. |
|---|
| 4 | * |
|---|
| 5 | * http://www.lockon.co.jp/ |
|---|
| 6 | */ |
|---|
| 7 | |
|---|
| 8 | /*---------------------------------------------------------------------- |
|---|
| 9 | * [̾¾Î] gfDownloadCsv |
|---|
| 10 | * [³µÍ×] °ú¿ô¥Ç¡¼¥¿¤òCSV¤È¤·¤Æ¡¢¥¯¥é¥¤¥¢¥ó¥È¤Ë¥À¥¦¥ó¥í¡¼¥É¤µ¤»¤ë |
|---|
| 11 | * [°ú¿ô] 1:¥Ø¥Ã¥Àʸ»úÎó 2:CSV¥Ç¡¼¥¿ |
|---|
| 12 | * [ÌáÃÍ] - |
|---|
| 13 | * [°Í¸] - |
|---|
| 14 | * [Ãí¼á] °ú¿ô¤Ï£±¡¤£²¤È¤â¥«¥ó¥Þ¶èÀÚ¤ê¤Ë¤Ê¤Ã¤Æ¤¤¤ë¤³¤È |
|---|
| 15 | *----------------------------------------------------------------------*/ |
|---|
| 16 | function gfDownloadCsv($header, $contents){ |
|---|
| 17 | |
|---|
| 18 | $fiest_name = date("YmdHis") .".csv"; |
|---|
| 19 | |
|---|
| 20 | /* HTTP¥Ø¥Ã¥À¤Î½ÐÎÏ */ |
|---|
| 21 | Header("Content-disposition: attachment; filename=${fiest_name}"); |
|---|
| 22 | Header("Content-type: application/octet-stream; name=${fiest_name}"); |
|---|
| 23 | |
|---|
| 24 | $return = $header.$contents; |
|---|
| 25 | if (mb_detect_encoding($return) == CHAR_CODE){ //ʸ»ú¥³¡¼¥ÉÊÑ´¹ |
|---|
| 26 | $return = mb_convert_encoding($return,'SJIS',CHAR_CODE); |
|---|
| 27 | $return = str_replace( array( "\r\n", "\r" ), "\n", $return); // ²þ¹ÔÊýË¡¤ÎÅý°ì |
|---|
| 28 | } |
|---|
| 29 | echo $return; |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | /*---------------------------------------------------------------------- |
|---|
| 33 | * [̾¾Î] gfSetCsv |
|---|
| 34 | * [³µÍ×] °ú¿ô¤ÎÇÛÎó¤òCSV·Á¼°¤ËÊÑ´¹¤¹¤ë |
|---|
| 35 | * [°ú¿ô] 1:CSV¤Ë¤¹¤ëÇÛÎó 2:°ú¿ô1¤¬Ï¢ÁÛÇÛÎó»þ¤Îꤍ»ú¤ò»ØÄꤷ¤¿ÇÛÎó |
|---|
| 36 | * [ÌáÃÍ] CSV¥Ç¡¼¥¿ |
|---|
| 37 | * [°Í¸] - |
|---|
| 38 | * [Ãí¼á] - |
|---|
| 39 | *----------------------------------------------------------------------*/ |
|---|
| 40 | function gfSetCsv( $array, $arrayIndex = "" ){ |
|---|
| 41 | //°ú¿ô$arrayIndex¤Ï¡¢$array¤¬Ï¢ÁÛÇÛÎó¤Î¤È¤¤Ëꤍ»ú¤ò»ØÄꤷ¤Æ¤ä¤ë¤¿¤á¤Ë»ÈÍѤ¹¤ë |
|---|
| 42 | |
|---|
| 43 | $return = ""; |
|---|
| 44 | for ($i=0; $i<count($array); $i++){ |
|---|
| 45 | |
|---|
| 46 | for ($j=0; $j<count($array[$i]); $j++ ){ |
|---|
| 47 | if ( $j > 0 ) $return .= ","; |
|---|
| 48 | $return .= "\""; |
|---|
| 49 | if ( $arrayIndex ){ |
|---|
| 50 | $return .= mb_ereg_replace("<","¡ã",mb_ereg_replace( "\"","\"\"",$array[$i][$arrayIndex[$j]] )) ."\""; |
|---|
| 51 | } else { |
|---|
| 52 | $return .= mb_ereg_replace("<","¡ã",mb_ereg_replace( "\"","\"\"",$array[$i][$j] )) ."\""; |
|---|
| 53 | } |
|---|
| 54 | } |
|---|
| 55 | $return .= "\n"; |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | return $return; |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | /*---------------------------------------------------------------------- |
|---|
| 62 | * [̾¾Î] gfGetAge |
|---|
| 63 | * [³µÍ×] ÆüÉÕ¤è¤êǯÎð¤ò·×»»¤¹¤ë¡£ |
|---|
| 64 | * [°ú¿ô] 1:ÆüÉÕʸ»úÎó(yyyy/mm/dd¡¢yyyy-mm-dd hh:mm:ssÅù) |
|---|
| 65 | * [ÌáÃÍ] ǯÎð¤Î¿ôÃÍ |
|---|
| 66 | * [°Í¸] - |
|---|
| 67 | * [Ãí¼á] - |
|---|
| 68 | *----------------------------------------------------------------------*/ |
|---|
| 69 | function gfGetAge($dbdate) |
|---|
| 70 | { |
|---|
| 71 | $ty = date("Y"); |
|---|
| 72 | $tm = date("m"); |
|---|
| 73 | $td = date("d"); |
|---|
| 74 | list($by, $bm, $bd) = split("[-/ ]", $dbdate); |
|---|
| 75 | $age = $ty - $by; |
|---|
| 76 | if($tm * 100 + $td < $bm * 100 + $bd) $age--; |
|---|
| 77 | return $age; |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | /*---------------------------------------------------------------------- |
|---|
| 81 | * [̾¾Î] gfDebugLog |
|---|
| 82 | * [³µÍ×] ¥í¥°¥Õ¥¡¥¤¥ë¤ËÊÑ¿ô¤Î¾ÜºÙ¤ò½ÐÎϤ¹¤ë¡£ |
|---|
| 83 | * [°ú¿ô] ÂоݤȤʤëÊÑ¿ô |
|---|
| 84 | * [ÌáÃÍ] ¤Ê¤· |
|---|
| 85 | * [°Í¸] gfPrintLog |
|---|
| 86 | * [Ãí¼á] - |
|---|
| 87 | *----------------------------------------------------------------------*/ |
|---|
| 88 | function gfDebugLog($obj){ |
|---|
| 89 | gfPrintLog("*** start Debug ***"); |
|---|
| 90 | ob_start(); |
|---|
| 91 | print_r($obj); |
|---|
| 92 | $buffer = ob_get_contents(); |
|---|
| 93 | ob_end_clean(); |
|---|
| 94 | $fp = fopen(LOG_PATH, "a+"); |
|---|
| 95 | fwrite( $fp, $buffer."\n" ); |
|---|
| 96 | fclose( $fp ); |
|---|
| 97 | gfPrintLog("*** end Debug ***"); |
|---|
| 98 | |
|---|
| 99 | // ¥í¥°¥Æ¡¼¥·¥ç¥ó |
|---|
| 100 | gfLogRotation(MAX_LOG_QUANTITY, MAX_LOG_SIZE, LOG_PATH); |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | /*---------------------------------------------------------------------- |
|---|
| 104 | * [̾¾Î] gfPrintLog |
|---|
| 105 | * [³µÍ×] ¥í¥°¥Õ¥¡¥¤¥ë¤ËÆü»þ¡¢½èÍý¥Õ¥¡¥¤¥ë̾¡¢¥á¥Ã¥»¡¼¥¸¤ò½ÐÎÏ |
|---|
| 106 | * [°ú¿ô] ɽ¼¨¤·¤¿¤¤¥á¥Ã¥»¡¼¥¸ |
|---|
| 107 | * [ÌáÃÍ] ¤Ê¤· |
|---|
| 108 | * [°Í¸] ¤Ê¤· |
|---|
| 109 | * [Ãí¼á] - |
|---|
| 110 | *----------------------------------------------------------------------*/ |
|---|
| 111 | function gfPrintLog($mess, $path = '') { |
|---|
| 112 | // ÆüÉդμèÆÀ |
|---|
| 113 | $today = date("Y/m/d H:i:s"); |
|---|
| 114 | // ½ÐÎϥѥ¹¤ÎºîÀ® |
|---|
| 115 | if ($path == "") { |
|---|
| 116 | $path = LOG_PATH; |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | // ¥¨¥¹¥±¡¼¥×¤µ¤ì¤Æ¤¤¤ëʸ»ú¤ò¤â¤È¤ËÌ᤹ |
|---|
| 120 | $trans_tbl = get_html_translation_table (HTML_ENTITIES); |
|---|
| 121 | $trans_tbl = array_flip ($trans_tbl); |
|---|
| 122 | $mess = strtr($mess, $trans_tbl); |
|---|
| 123 | |
|---|
| 124 | $fp = fopen($path, "a+"); |
|---|
| 125 | if($fp) { |
|---|
| 126 | fwrite( $fp, $today." [".$_SERVER['PHP_SELF']."] ".$mess." from ". $_SERVER['REMOTE_ADDR']. "\n" ); |
|---|
| 127 | fclose( $fp ); |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | // ¥í¥°¥Æ¡¼¥·¥ç¥ó |
|---|
| 131 | gfLogRotation(MAX_LOG_QUANTITY, MAX_LOG_SIZE, $path); |
|---|
| 132 | } |
|---|
| 133 | |
|---|
| 134 | /** |
|---|
| 135 | * ¥í¥°¥í¡¼¥Æ¡¼¥·¥ç¥óµ¡Ç½ |
|---|
| 136 | * |
|---|
| 137 | * @param integer $max_log ºÇÂç¥Õ¥¡¥¤¥ë¿ô |
|---|
| 138 | * @param integer $max_size ºÇÂ祵¥¤¥º |
|---|
| 139 | * @param string $path ¥Õ¥¡¥¤¥ë¥Ñ¥¹ |
|---|
| 140 | * @return void ¤Ê¤· |
|---|
| 141 | */ |
|---|
| 142 | function gfLogRotation($max_log, $max_size, $path) { |
|---|
| 143 | |
|---|
| 144 | // ¥Ç¥£¥ì¥¯¥È¥ê̾¤ò¼èÆÀ |
|---|
| 145 | $dirname = dirname($path); |
|---|
| 146 | // ¥Õ¥¡¥¤¥ë̾¤ò¼èÆÀ |
|---|
| 147 | $basename = basename($path); |
|---|
| 148 | |
|---|
| 149 | // ¥Õ¥¡¥¤¥ë¤¬ºÇÂ祵¥¤¥º¤òͤ¨¤Æ¤¤¤Ê¤¤¤«¥Á¥§¥Ã¥¯ |
|---|
| 150 | if(filesize($path) > $max_size) { |
|---|
| 151 | if ($dh = opendir($dirname)) { |
|---|
| 152 | while (($file = readdir($dh)) !== false) { |
|---|
| 153 | // ¥í¥°¥í¡¼¥Æ¡¼¥·¥ç¥ó¤Ë¤ÆºîÀ®¤µ¤ì¤¿¥Õ¥¡¥¤¥ë¤ò¼èÆÀ |
|---|
| 154 | if(ereg("^". $basename . "\." , $file)) { |
|---|
| 155 | $arrLog[] = $file; |
|---|
| 156 | } |
|---|
| 157 | } |
|---|
| 158 | |
|---|
| 159 | // ¥Õ¥¡¥¤¥ë¥í¥°¤¬ºÇÂç¸Ä¿ô¤Ê¤é°Ê¾å¤Ê¤é¸Å¤¤¥Õ¥¡¥¤¥ë¤«¤éºï½ü¤¹¤ë |
|---|
| 160 | $count = count($arrLog); |
|---|
| 161 | if($count >= $max_log) { |
|---|
| 162 | $diff = $count - $max_log; |
|---|
| 163 | for($i = 0; $diff >= $i ; $i++) { |
|---|
| 164 | unlink($dirname. "/" .array_pop($arrLog)); |
|---|
| 165 | } |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | // ¥í¥°¥Õ¥¡¥¤¥ë¤Îꤍ»ú¤ò¤º¤é¤¹ |
|---|
| 169 | $count = count($arrLog); |
|---|
| 170 | for($i = $count; 1 <= $i; $i--) { |
|---|
| 171 | $move_number = $i + 1; |
|---|
| 172 | |
|---|
| 173 | if(file_exists("$path.$move_number")) unlink("$path.$move_number"); |
|---|
| 174 | copy("$dirname/" . $arrLog[$i - 1], "$path.$move_number"); |
|---|
| 175 | |
|---|
| 176 | } |
|---|
| 177 | $ret = copy($path, "$path.1"); |
|---|
| 178 | |
|---|
| 179 | // ¿·µ¬¥í¥°¥Õ¥¡¥¤¥ë¤òºîÀ® |
|---|
| 180 | if($ret) { |
|---|
| 181 | unlink($path); |
|---|
| 182 | touch($path); |
|---|
| 183 | } |
|---|
| 184 | } |
|---|
| 185 | } |
|---|
| 186 | } |
|---|
| 187 | |
|---|
| 188 | /*---------------------------------------------------------------------- |
|---|
| 189 | * [̾¾Î] gfMakePassword |
|---|
| 190 | * [³µÍ×] ¥é¥ó¥À¥à¥Ñ¥¹¥ï¡¼¥ÉÀ¸À®¡Ê±Ñ¿ô»ú¡Ë |
|---|
| 191 | * [°ú¿ô] ¥Ñ¥¹¥ï¡¼¥É¤Î·å¿ô |
|---|
| 192 | * [ÌáÃÍ] ¥é¥ó¥À¥àÀ¸À®¤µ¤ì¤¿¥Ñ¥¹¥ï¡¼¥É |
|---|
| 193 | * [°Í¸] ¤Ê¤· |
|---|
| 194 | * [Ãí¼á] - |
|---|
| 195 | *----------------------------------------------------------------------*/ |
|---|
| 196 | function gfMakePassword($pwLength) { |
|---|
| 197 | |
|---|
| 198 | // Íð¿ôɽ¤Î¥·¡¼¥É¤ò·èÄê |
|---|
| 199 | srand((double)microtime() * 54234853); |
|---|
| 200 | |
|---|
| 201 | // ¥Ñ¥¹¥ï¡¼¥Éʸ»úÎó¤ÎÇÛÎó¤òºîÀ® |
|---|
| 202 | $character = "abcdefghkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ2345679"; |
|---|
| 203 | $pw = preg_split("//", $character, 0, PREG_SPLIT_NO_EMPTY); |
|---|
| 204 | |
|---|
| 205 | $password = ""; |
|---|
| 206 | for($i = 0; $i<$pwLength; $i++ ) { |
|---|
| 207 | $password .= $pw[array_rand($pw, 1)]; |
|---|
| 208 | } |
|---|
| 209 | |
|---|
| 210 | return $password; |
|---|
| 211 | } |
|---|
| 212 | |
|---|
| 213 | /*---------------------------------------------------------------------- |
|---|
| 214 | * [̾¾Î] sf_explodeExt |
|---|
| 215 | * [³µÍ×] ¥Õ¥¡¥¤¥ë¤Î³ÈÄ¥»Ò¼èÆÀ |
|---|
| 216 | * [°ú¿ô] ¥Õ¥¡¥¤¥ë̾ |
|---|
| 217 | * [ÌáÃÍ] ³ÈÄ¥»Ò |
|---|
| 218 | * [°Í¸] ¤Ê¤· |
|---|
| 219 | * [Ãí¼á] - |
|---|
| 220 | *----------------------------------------------------------------------*/ |
|---|
| 221 | function gf_explodeExt($fileName) { |
|---|
| 222 | $ext1 = explode(".", $fileName); |
|---|
| 223 | $ext2 = $ext1[count($ext1) - 1]; |
|---|
| 224 | $ext2 = strtolower($ext2); |
|---|
| 225 | return $ext2; |
|---|
| 226 | } |
|---|
| 227 | |
|---|
| 228 | |
|---|
| 229 | /*---------------------------------------------------------------------------------------------------------------------- |
|---|
| 230 | * [̾¾Î] gfMailHeaderAddr |
|---|
| 231 | * [³µÍ×] ÆþÎϤµ¤ì¤¿¥á¡¼¥ë¥¢¥É¥ì¥¹¤ò¥á¡¼¥ë´Ø¿ôÍѤΰ¸Àè¤ËÊÑ´¹ |
|---|
| 232 | * [°ú¿ô] ¡Ö¥á¡¼¥ë¥¢¥É¥ì¥¹¡×¤Þ¤¿¤Ï¡Ö̾Á°<¥á¡¼¥ë¥¢¥É¥ì¥¹>¡×¡¢Ê£¿ô¥¢¥É¥ì¥¹»ØÄê»þ¤Ï¥«¥ó¥Þ¶èÀÚ¤ê¤Ç»ØÄꤹ¤ë¡£ |
|---|
| 233 | * [ÌáÃÍ] ¡Ö¥á¡¼¥ë¥¢¥É¥ì¥¹¡×¤Þ¤¿¤Ï¡ÖJIS_MIME¤Ë¥³¡¼¥ÉÊÑ´¹¤·¤¿Ì¾Á° <¥á¡¼¥ë¥¢¥É¥ì¥¹>¡×¡¢Ê£¿ô¥¢¥É¥ì¥¹»ØÄê»þ¤Ï¥«¥ó¥Þ¶èÀÚ¤ê¤ÇÊֵѤ¹¤ë¡£ |
|---|
| 234 | * [°Í¸] ¤Ê¤· |
|---|
| 235 | * [Ãí¼á] - |
|---|
| 236 | *----------------------------------------------------------------------------------------------------------------------*/ |
|---|
| 237 | |
|---|
| 238 | function gfMailHeaderAddr($str) { |
|---|
| 239 | $addrs = explode(",", $str); //¥¢¥É¥ì¥¹¤òÇÛÎó¤ËÆþ¤ì¤ë |
|---|
| 240 | foreach ($addrs as $addr) { |
|---|
| 241 | if (preg_match("/^(.+)<(.+)>$/", $addr, $matches)) { |
|---|
| 242 | //°ú¿ô¤¬¡Ö̾Á°<¥á¡¼¥ë¥¢¥É¥ì¥¹>¡×¤Î¾ì¹ç |
|---|
| 243 | $mailaddrs[] = mb_encode_mimeheader(trim($matches[1]))." <".trim($matches[2]).">"; |
|---|
| 244 | } else { |
|---|
| 245 | //¥á¡¼¥ë¥¢¥É¥ì¥¹¤Î¤ß¤Î¾ì¹ç |
|---|
| 246 | $mailaddrs[] = trim($addr); |
|---|
| 247 | } |
|---|
| 248 | } |
|---|
| 249 | return implode(", ", $mailaddrs); //Ê£¿ô¥¢¥É¥ì¥¹¤Ï¥«¥ó¥Þ¶èÀÚ¤ê¤Ë¤¹¤ë |
|---|
| 250 | } |
|---|
| 251 | ?> |
|---|