source: branches/mobile/data/lib/glib.php @ 8524

Revision 8524, 5.9 KB checked in by kakinaka, 16 years ago (diff)

blank

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1<?php
2/*
3 * Copyright(c) 2000-2006 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 *----------------------------------------------------------------------*/
16function 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 *----------------------------------------------------------------------*/
40function 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 *----------------------------------------------------------------------*/
69function 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 *----------------------------------------------------------------------*/
88function 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/*----------------------------------------------------------------------
101 * [̾¾Î] gfPrintLog
102 * [³µÍ×] ¥í¥°¥Õ¥¡¥¤¥ë¤ËÆü»þ¡¢½èÍý¥Õ¥¡¥¤¥ë̾¡¢¥á¥Ã¥»¡¼¥¸¤ò½ÐÎÏ
103 * [°ú¿ô] ɽ¼¨¤·¤¿¤¤¥á¥Ã¥»¡¼¥¸
104 * [ÌáÃÍ] ¤Ê¤·
105 * [°Í¸] ¤Ê¤·
106 * [Ãí¼á] -
107 *----------------------------------------------------------------------*/
108function gfPrintLog($mess, $path = '') {
109    // ÆüÉդμèÆÀ
110    $today = date("Y/m/d H:i:s");
111    // ½ÐÎϥѥ¹¤ÎºîÀ®
112    if ($path == "") {
113        $path = LOG_PATH;
114    }
115
116    // ¥¨¥¹¥±¡¼¥×¤µ¤ì¤Æ¤¤¤ëʸ»ú¤ò¤â¤È¤ËÌ᤹
117    $trans_tbl = get_html_translation_table (HTML_ENTITIES);
118    $trans_tbl = array_flip ($trans_tbl);
119    $mess = strtr($mess, $trans_tbl);
120
121    $fp = fopen($path, "a+");
122    if($fp) {
123        fwrite( $fp, $today." [".$_SERVER['PHP_SELF']."] ".$mess." from ". $_SERVER['REMOTE_ADDR']. "\n" );
124        fclose( $fp );
125    }
126}
127
128/*----------------------------------------------------------------------
129 * [̾¾Î] gfMakePassword
130 * [³µÍ×] ¥é¥ó¥À¥à¥Ñ¥¹¥ï¡¼¥ÉÀ¸À®¡Ê±Ñ¿ô»ú¡Ë
131 * [°ú¿ô] ¥Ñ¥¹¥ï¡¼¥É¤Î·å¿ô
132 * [ÌáÃÍ] ¥é¥ó¥À¥àÀ¸À®¤µ¤ì¤¿¥Ñ¥¹¥ï¡¼¥É
133 * [°Í¸] ¤Ê¤·
134 * [Ãí¼á] -
135 *----------------------------------------------------------------------*/
136function gfMakePassword($pwLength) {
137   
138    // Íð¿ôɽ¤Î¥·¡¼¥É¤ò·èÄê
139    srand((double)microtime() * 54234853);
140   
141    // ¥Ñ¥¹¥ï¡¼¥Éʸ»úÎó¤ÎÇÛÎó¤òºîÀ®
142    $character = "abcdefghkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ2345679";
143    $pw = preg_split("//", $character, 0, PREG_SPLIT_NO_EMPTY);
144   
145    $password = "";
146    for($i = 0; $i<$pwLength; $i++ ) {
147        $password .= $pw[array_rand($pw, 1)];
148    }
149
150    return $password;
151}
152
153/*----------------------------------------------------------------------
154 * [̾¾Î] sf_explodeExt
155 * [³µÍ×] ¥Õ¥¡¥¤¥ë¤Î³ÈÄ¥»Ò¼èÆÀ
156 * [°ú¿ô] ¥Õ¥¡¥¤¥ë̾
157 * [ÌáÃÍ] ³ÈÄ¥»Ò
158 * [°Í¸] ¤Ê¤·
159 * [Ãí¼á] -
160 *----------------------------------------------------------------------*/
161function gf_explodeExt($fileName) {
162    $ext1 = explode(".", $fileName);
163    $ext2 = $ext1[count($ext1) - 1];
164    $ext2 = strtolower($ext2);
165    return $ext2;
166}
167
168
169/*----------------------------------------------------------------------------------------------------------------------
170 * [̾¾Î] gfMailHeaderAddr
171 * [³µÍ×] ÆþÎϤµ¤ì¤¿¥á¡¼¥ë¥¢¥É¥ì¥¹¤ò¥á¡¼¥ë´Ø¿ôÍѤΰ¸Àè¤ËÊÑ´¹
172 * [°ú¿ô] ¡Ö¥á¡¼¥ë¥¢¥É¥ì¥¹¡×¤Þ¤¿¤Ï¡Ö̾Á°<¥á¡¼¥ë¥¢¥É¥ì¥¹>¡×¡¢Ê£¿ô¥¢¥É¥ì¥¹»ØÄê»þ¤Ï¥«¥ó¥Þ¶èÀÚ¤ê¤Ç»ØÄꤹ¤ë¡£
173 * [ÌáÃÍ] ¡Ö¥á¡¼¥ë¥¢¥É¥ì¥¹¡×¤Þ¤¿¤Ï¡ÖJIS_MIME¤Ë¥³¡¼¥ÉÊÑ´¹¤·¤¿Ì¾Á° <¥á¡¼¥ë¥¢¥É¥ì¥¹>¡×¡¢Ê£¿ô¥¢¥É¥ì¥¹»ØÄê»þ¤Ï¥«¥ó¥Þ¶èÀÚ¤ê¤ÇÊֵѤ¹¤ë¡£
174 * [°Í¸] ¤Ê¤·
175 * [Ãí¼á] -
176 *----------------------------------------------------------------------------------------------------------------------*/
177
178function gfMailHeaderAddr($str) {
179    $addrs = explode(",", $str); //¥¢¥É¥ì¥¹¤òÇÛÎó¤ËÆþ¤ì¤ë
180    foreach ($addrs as $addr) {
181        if (preg_match("/^(.+)<(.+)>$/", $addr, $matches)) {
182            //°ú¿ô¤¬¡Ö̾Á°<¥á¡¼¥ë¥¢¥É¥ì¥¹>¡×¤Î¾ì¹ç
183            $mailaddrs[] = mb_encode_mimeheader(trim($matches[1]))." <".trim($matches[2]).">";
184        } else {
185            //¥á¡¼¥ë¥¢¥É¥ì¥¹¤Î¤ß¤Î¾ì¹ç
186            $mailaddrs[] =  trim($addr);
187        }
188    }
189    return implode(", ", $mailaddrs); //Ê£¿ô¥¢¥É¥ì¥¹¤Ï¥«¥ó¥Þ¶èÀÚ¤ê¤Ë¤¹¤ë
190}
191?>
Note: See TracBrowser for help on using the repository browser.