PageRenderTime 83ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/databox/lib/databox_functions.inc

https://bitbucket.org/tsuchi/box
PHP | 6042 lines | 4490 code | 704 blank | 848 comment | 503 complexity | d1c88d862136135df058d0f9d1a966d4 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /* Reminder: always indent with 4 spaces (no tabs). */
  3. // +---------------------------------------------------------------------------+
  4. // | DataBox プラグイン function.inc からrequire
  5. // | Box シリーズ共通
  6. // +---------------------------------------------------------------------------+
  7. // $Id: plugins/databox/lib/databox_functions.inc
  8. //20100818 tsuchitani AT ivywe DOT co DOT jp http://www.ivywe.co.jp/
  9. if (strpos ($_SERVER['PHP_SELF'], 'databox_functions.inc') !== false) {
  10. die ('This file can not be used on its own.');
  11. }
  12. //==============================================================================
  13. function DATABOX_nl2br (
  14. $text
  15. )
  16. // +---------------------------------------------------------------------------+
  17. // | 機能 改行をBRに変換
  18. // | 書式 DATABOX_nl2br ($text)
  19. // +---------------------------------------------------------------------------+
  20. // | 引数 $text:文字列
  21. // +---------------------------------------------------------------------------+
  22. // | 戻値 nomal:改行をBRに変換後の文字列
  23. // +---------------------------------------------------------------------------+
  24. // copy20100803 from "hiroron - 改行をBRに変換"
  25. {
  26. return PLG_replacetags ( str_replace(array("\r\n","\r","\n"), '<br'.XHTML.'>', $text) );
  27. }
  28. function DATABOX_autolink (
  29. $text
  30. )
  31. // +---------------------------------------------------------------------------+
  32. // | 機能 urlをリンク変換
  33. // | 書式 DATABOX_autolink($text)
  34. // +---------------------------------------------------------------------------+
  35. // | 引数 $text :文字列 |
  36. // +---------------------------------------------------------------------------+
  37. // | 戻値 nomal:urlをリンク変換後の文字列 |
  38. // +---------------------------------------------------------------------------+
  39. // copy20100803 from "hiroron - 自動リンクを
  40. {
  41. $patterns = array("/(https?|ftp)(:\/\/[[:alnum:]\+\$\;\?\.%,!#~*\/:@&=_-]+)/i");
  42. $replacements = array("<a href=\"\\1\\2\" target=\"_blank\">\\1\\2</a>");
  43. return preg_replace($patterns, $replacements, $text);
  44. }
  45. function DATABOX_codetoid(
  46. $code
  47. ,$table
  48. ,$idname = "id"
  49. ,$codename = "code"
  50. )
  51. // +---------------------------------------------------------------------------+
  52. // | 機能 コードをidに変換
  53. // | 書式 DATABOX_codetoid($code,'DATABOX_base')
  54. // | 書式 DATABOX_codetoid($code,'users',"uid","username")
  55. // +---------------------------------------------------------------------------+
  56. // | 引数 $code:コード
  57. // | 引数 $table
  58. // | 引数 $idname
  59. // | 引数 $codename
  60. // +---------------------------------------------------------------------------+
  61. // | 戻値 nomal:id
  62. // +---------------------------------------------------------------------------+
  63. //update20101125
  64. {
  65. global $_TABLES;
  66. $retval=DB_getItem( $_TABLES[$table] ,$idname,$codename."='{$code}'");
  67. if (empty($retval)){
  68. $retval=0;
  69. }
  70. return $retval;
  71. }
  72. function DATABOX_swichlang(
  73. $code
  74. )
  75. // +---------------------------------------------------------------------------+
  76. // | 機能 コード多言語対応変換
  77. // | 書式 DATABOX_swichlang($code)
  78. // | xxxx_(言語id) 多言語モードの時に必要があれば言語idを現在の言語idに変換
  79. // +---------------------------------------------------------------------------+
  80. // | 引数 $code:コード
  81. // +---------------------------------------------------------------------------+
  82. // | 戻値 nomal:変換後のコード
  83. // +---------------------------------------------------------------------------+
  84. {
  85. global $_CONF;
  86. $newlanguageid = COM_getLanguageId();
  87. if ($newlanguageid<>""){
  88. if ($code<>""){
  89. $lang_len = strlen($newlanguageid);
  90. $oldlanguageid=substr($code,-($lang_len));
  91. if (array_key_exists($oldlanguageid, $_CONF['language_files'])){
  92. $code = substr_replace($code, $newlanguageid, -$lang_len);
  93. }
  94. }
  95. }
  96. return $code;
  97. }
  98. function DATABOX_templatePath (
  99. $kind = 'data'
  100. ,$template ='default'
  101. ,$pi_name= 'databox'
  102. )
  103. // +---------------------------------------------------------------------------+
  104. // | 機能 テンプレートフォルダパスを取得
  105. // | 書式 DATABOX_templatePath('data','default','databox')
  106. // | 書式 DATABOX_templatePath($kind,$template,$pi_name)
  107. // +---------------------------------------------------------------------------+
  108. // | 引数 $kind:'data' 'category' ''newlist' 'admin'
  109. // | 引数 $template: 'default'
  110. // | 引数 $pi_name: 'databox' 'userbox' 'formbox'
  111. // +---------------------------------------------------------------------------+
  112. // | 戻値 :テンプレートフォルダパス
  113. // +---------------------------------------------------------------------------+
  114. // 20101115
  115. {
  116. global $_CONF;
  117. if (is_null($template) OR ($template==="")){
  118. $template="default";
  119. }
  120. $box_conf="_".strtoupper($pi_name)."_CONF";
  121. global $$box_conf;
  122. $box_conf=$$box_conf;
  123. if ($kind==="admin"){
  124. $conf_templates=$box_conf["templates_admin"];
  125. }else{
  126. $conf_templates=$box_conf["templates"];
  127. }
  128. //"standard";//標準テンプレートを使用する
  129. //"custom";//カスタムテンプレートを使用する
  130. //"theme";//テーマテンプレートを使用する
  131. if ($conf_templates==="theme"){
  132. $tmplfld=$_CONF['path_layout'] .$box_conf['themespath'].$kind;
  133. if ($kind<>"admin"){
  134. $tmplfld.="/".$template;
  135. }
  136. if (is_dir($tmplfld)) {
  137. }else{
  138. COM_handle404();
  139. exit;
  140. }
  141. }else if ($conf_templates==="custom"){
  142. $tmplfld=$_CONF['path'] .'plugins/'.$pi_name.'/custom/templates/'.$kind;
  143. if ($kind<>"admin"){
  144. $tmplfld.="/".$template;
  145. }
  146. if (is_dir($tmplfld)){
  147. }else{
  148. COM_handle404();
  149. exit;
  150. }
  151. }else{
  152. $tmplfld=$_CONF['path'] .'plugins/'.$pi_name.'/templates/'.$kind;
  153. if ($kind<>"admin"){
  154. $tmplfld.="/default";
  155. }
  156. }
  157. return $tmplfld;
  158. }
  159. function DATABOX_siteHeader (
  160. $pi_name= 'databox'
  161. ,$kind = ''
  162. ,$page_title = ''
  163. ,$headercode = ''
  164. )
  165. // +---------------------------------------------------------------------------+
  166. // | 機能 ヘッダを編集
  167. // | 書式 DATABOX_siteHeader($pi_name,'_admin',$page_title,$headercode)
  168. // | 書式 DATABOX_siteHeader($pi_name,'_admin',$page_title)
  169. // +---------------------------------------------------------------------------+
  170. // | 引数 $pi_name: 'databox' 'userbox' 'formbox'
  171. // | 引数 $kind:'' '_admin'
  172. // | 引数 $pagetitle:
  173. // | 引数 $headercode:
  174. // +---------------------------------------------------------------------------+
  175. // | 戻値 :ヘッダ
  176. // +---------------------------------------------------------------------------+
  177. // 20120910
  178. {
  179. global $_CONF;
  180. $box_conf="_".strtoupper($pi_name)."_CONF";
  181. global $$box_conf;
  182. $box_conf=$$box_conf;
  183. $display="";
  184. if ($kind=="_admin" OR $kind==""){
  185. $layout=$box_conf['layout'.$kind];
  186. }else{
  187. $layout=$kind;
  188. }
  189. switch ($layout) {
  190. // ヘッダ・フッタ・左ブロックあり(右ブロックはテーマ設定による)
  191. case 'standard':
  192. //ヘッダ・フッタ・左右ブロックあり
  193. case 'leftrightblocks':
  194. //ヘッダ・フッタ・左ブロックあり(右ブロックなし)
  195. case 'leftblocks':
  196. $display=COM_siteHeader ('menu', $page_title,$headercode);
  197. break;
  198. //ヘッダ・フッタ・右ブロックあり(左ブロックなし)
  199. case 'rightblocks':
  200. //ヘッダ・フッタあり(ブロックなし)
  201. case 'noblocks':
  202. $display=COM_siteHeader ('none', $page_title,$headercode);
  203. break;
  204. //全画面表示(ヘッダ・フッタ・ブロックなし)
  205. case 'blankpage':
  206. break;
  207. default:
  208. }
  209. return $display;
  210. }
  211. function DATABOX_siteFooter (
  212. $pi_name= 'databox'
  213. ,$kind = ''
  214. ,$custom=''
  215. )
  216. // +---------------------------------------------------------------------------+
  217. // | 機能 フッタを編集
  218. // | 書式 DATABOX_siteFooter($pi_name,'_admin',$custom)
  219. // | 書式 DATABOX_siteFooter($pi_name)
  220. // +---------------------------------------------------------------------------+
  221. // | 引数 $pi_name: 'databox' 'userbox' 'formbox'
  222. // | 引数 $kind:'' '_admin'
  223. // | 引数 $custom:
  224. // +---------------------------------------------------------------------------+
  225. // | 戻値 : フッタ
  226. // +---------------------------------------------------------------------------+
  227. // 20110119
  228. {
  229. global $_CONF;
  230. if (is_null($pi_name)){
  231. $pi_name="databox";
  232. }
  233. $box_conf="_".strtoupper($pi_name)."_CONF";
  234. global $$box_conf;
  235. $box_conf=$$box_conf;
  236. $display="";
  237. $layout=$box_conf['layout'.$kind];
  238. switch ($layout) {
  239. // ヘッダ・フッタ・左ブロックあり(右ブロックはテーマ設定による)
  240. case 'standard':
  241. $display .= COM_siteFooter(false,$custom);
  242. break;
  243. //ヘッダ・フッタ・左右ブロックあり
  244. case 'leftrightblocks':
  245. //ヘッダ・フッタ・右ブロックあり(左ブロックなし)
  246. case 'rightblocks':
  247. $display .= COM_siteFooter(true,$custom);
  248. break;
  249. //ヘッダ・フッタ・左ブロックあり(右ブロックなし)
  250. case 'leftblocks':
  251. //ヘッダ・フッタあり(ブロックなし)
  252. // 右ブロックを常時表示する設定であっても右ブロックを表示させない
  253. case 'noblocks':
  254. $_CONF['show_right_blocks']=0;
  255. $_CONF['left_blocks_in_footer']=0;
  256. $display .= COM_siteFooter(false,$custom);
  257. break;
  258. //全画面表示(ヘッダ・フッタ・ブロックなし)
  259. case 'blankpage':
  260. break;
  261. default:
  262. }
  263. return $display;
  264. }
  265. //$retval = SP_returnStaticpage($page, $display_mode, $comment_order, $comment_mode, $comment_page, $msg, $query);
  266. function DATABOX_displaypage (
  267. $pi_name= 'databox'
  268. ,$kind = ''
  269. ,$display = ''
  270. ,$information = ''
  271. )
  272. //$information
  273. // 'what' 'none' no left blocks are returned
  274. // 'menu' (default) right blocks are returned
  275. // 'pagetitle' Optional content for the page's <title>
  276. // 'breadcrumbs' Optional content for the page's <title>
  277. // 'headercode' Optional code to go into the page's <head>
  278. // 'rightblock' 右ブロックを表示するかどうか  default is no (-1)
  279. // 'custom' An array defining custom function to be used to
  280. {
  281. global $_CONF;
  282. $box_conf="_".strtoupper($pi_name)."_CONF";
  283. global $$box_conf;
  284. $box_conf=$$box_conf;
  285. if ($kind=="_admin" OR $kind==""){
  286. $layout=$box_conf['layout'.$kind];
  287. }else{
  288. $layout=$kind;
  289. }
  290. //全画面表示(ヘッダ・フッタ・ブロックなし)
  291. if ($layout=='blankpage'){
  292. }else{
  293. switch ($layout) {
  294. // ヘッダ・フッタ・左ブロックあり(右ブロックはテーマ設定による)
  295. case 'standard':
  296. //$display=COM_siteHeader ('menu', $page_title,$headercode);
  297. //$display .= COM_siteFooter(false,$custom);
  298. $information['what']='menu';
  299. $information['rightblock']=false;
  300. break;
  301. //ヘッダ・フッタ・左右ブロックあり
  302. case 'leftrightblocks':
  303. //$display=COM_siteHeader ('menu', $page_title,$headercode);
  304. //$display .= COM_siteFooter(true,$custom);
  305. $information['what']='menu';
  306. $information['rightblock']=true;
  307. break;
  308. //ヘッダ・フッタ・左ブロックあり(右ブロックなし)
  309. case 'leftblocks':
  310. //$display=COM_siteHeader ('menu', $page_title,$headercode);
  311. $information['what']='menu';
  312. $_CONF['show_right_blocks']=0;
  313. $_CONF['left_blocks_in_footer']=0;
  314. //$display .= COM_siteFooter(false,$custom);
  315. $information['rightblock']=false;
  316. break;
  317. //ヘッダ・フッタ・右ブロックあり(左ブロックなし)
  318. case 'rightblocks':
  319. //$display=COM_siteHeader ('none', $page_title,$headercode);
  320. $information['what']='none';
  321. //$display .= COM_siteFooter(true,$custom);
  322. $information['rightblock']=true;
  323. break;
  324. //ヘッダ・フッタあり(ブロックなし)
  325. case 'noblocks':
  326. //$display=COM_siteHeader ('none', $page_title,$headercode);
  327. $information['what']='none';
  328. $_CONF['show_right_blocks']=0;
  329. $_CONF['left_blocks_in_footer']=0;
  330. //$display .= COM_siteFooter(false,$custom);
  331. $information['rightblock']=false;
  332. break;
  333. }
  334. //FOR GL2.0.0
  335. if (COM_versionCompare(VERSION, "2.0.0", '>=')){
  336. $display = COM_createHTMLDocument($display,$information);
  337. }else{
  338. $display = COM_siteHeader ($information['what'], $information['pagetitle']).$display;
  339. $display .= COM_siteFooter($information['rightblock']);
  340. }
  341. }
  342. return $display;
  343. }
  344. function DATABOX_getcheckList(
  345. $kind
  346. ,$selected
  347. ,$pi_name
  348. ,$group_id=""
  349. ,$fname=""
  350. )
  351. // +---------------------------------------------------------------------------+
  352. // | 機能 チェックリスト作成
  353. // | 書式 DATABOX_getcheckList($kind,$selected = "")
  354. // | 書式 $checklist=DATABOX_getcheckList ("fieldset","",$pi_name)
  355. // | 書式 $checklist=DATABOX_getcheckList ("categorygroup","",$pi_name,1,"ch1")
  356. // +---------------------------------------------------------------------------+
  357. // | 引数 $kind:fieldset
  358. // | 引数 $selected:選択値
  359. // | 引数 $pi_name:plugin name 'databox' 'userbox' 'formbox'
  360. // | 引数 $group_id マスターの時既定リスト名
  361. // | 引数 $fname フィールド名
  362. // +---------------------------------------------------------------------------+
  363. // | 戻値 nomal:チェックリスト
  364. // +---------------------------------------------------------------------------+
  365. //20101116
  366. // カテゴリ以外で使っているか確認のこと --> category は DATABOX_getcategoriesinp
  367. //20140624 fieldset 追加
  368. {
  369. global $_TABLES;
  370. if ($fname==""){
  371. $fname=$kind;
  372. }
  373. $table_def_category=$_TABLES[strtoupper($pi_name).'_def_category'];
  374. $table_def_group=$_TABLES[strtoupper($pi_name).'_def_group'];
  375. $table_mst=$_TABLES[strtoupper($pi_name).'_mst'];
  376. $table_def_fieldset=$_TABLES[strtoupper($pi_name).'_def_fieldset'];
  377. $retval = '';
  378. if ($kind=="categorygroup"){
  379. $sql = "SELECT ";
  380. $sql .= " m1.category_id".LB;
  381. $sql .= ",m1.name".LB;
  382. $sql .= ",m1.orderno".LB;
  383. $sql .= ",m2.group_id".LB;
  384. $sql .= ",m2.name AS group_name".LB;
  385. $sql .= " FROM {$table_def_category} AS m1".LB;
  386. $sql .= " , {$table_def_group} AS m2".LB;
  387. $sql .= " WHERE ".LB;
  388. $sql .= " m1.allow_display<2 ".LB;
  389. $sql .= " AND m1.categorygroup_id =".$group_id.LB;
  390. $sql .= " AND m2.group_id = m1.categorygroup_id".LB;
  391. $sql .= " ORDER BY m1.orderno".LB;
  392. }else if ($kind=="fieldset"){
  393. $sql = "SELECT ";
  394. $sql .= " fieldset_id".LB;
  395. $sql .= ",name".LB;
  396. $sql .= ",'1' AS group_id".LB;
  397. $sql .= " FROM {$table_def_fieldset} ".LB;
  398. $sql .= " ORDER BY fieldset_id".LB;
  399. }else{
  400. $sql = "SELECT ".LB;
  401. $sql .= " no".LB;
  402. $sql .= ",value".LB;
  403. $sql .= ",orderno".LB;
  404. $sql .= ",'1' AS group_id".LB;
  405. $sql .= " FROM {$table_mst}".LB;
  406. $sql .= " WHERE kind='{$kind}'".LB;
  407. $sql .= " ORDER BY orderno".LB;
  408. }
  409. $result = DB_query( $sql );
  410. $nrows = DB_numRows( $result );
  411. if (is_array($selected)){
  412. $S = $selected;
  413. }else{
  414. if( !empty( $selected )) {
  415. $S = explode( ' ', $selected );
  416. }else {
  417. $S = array();
  418. }
  419. }
  420. $old_group_id="";
  421. for( $i = 0; $i < $nrows; $i++ ) {
  422. $A = DB_fetchArray( $result, true );
  423. $retval .= '<span style="white-space:nowrap">';
  424. $retval .= '<input type="checkbox" name="' . $fname . '[]" value="' . $A[0] ;
  425. $retval .= '"';
  426. for( $x = 0; $x < sizeof( $S ); $x++ ) {
  427. if( $A[0] == $S[$x] ) {
  428. $retval .= ' checked="checked"';
  429. }
  430. }
  431. $retval .= '>' . stripslashes( $A[1] ) . '</span>' . LB;
  432. }
  433. return $retval;
  434. }
  435. function DATABOX_getdatas(
  436. $fld
  437. ,$tbl
  438. ,$where
  439. )
  440. // +---------------------------------------------------------------------------+
  441. // | 機能 複数データ読込 |
  442. // | 書式 DATABOX_getdatas($fld,$tbl,$where) |
  443. // | $rt=DATABOX_getdatas( |
  444. // | "category_id",$_TABLES['DATABOX_category'],"id=$id"); |
  445. // +---------------------------------------------------------------------------+
  446. // | 引数 $fld:項目
  447. // | 引数 $tbl:テーブル
  448. // | 引数 $where:条件式
  449. // +---------------------------------------------------------------------------+
  450. // | 戻値 nomal:複数データリスト
  451. // +---------------------------------------------------------------------------+
  452. //update20100420
  453. {
  454. $sql="SELECT {$fld} FROM {$tbl} WHERE {$where}";
  455. $result = DB_query ($sql);
  456. $numrows = DB_numRows ($result);
  457. $selected="";
  458. for ($i = 0; $i < $numrows; $i++) {
  459. $A = DB_fetchArray ($result);
  460. $selected.= $A[$fld]." ";
  461. }
  462. $selcted=rtrim($selected," ");
  463. return $selected;
  464. }
  465. function DATABOX_savedatas(
  466. $fld
  467. ,$tbl
  468. ,$id
  469. ,$fldary=""
  470. )
  471. // +---------------------------------------------------------------------------+
  472. // | 機能 複数データ書込
  473. // | 書式 DATABOX_savedatas($fld,$tbl,$id,$fldary)
  474. // +---------------------------------------------------------------------------+
  475. // | 引数 $fld:項目
  476. // | 引数 $tbl:テーブル
  477. // | 引数 $id:
  478. // | 引数 $fldary:データ配列
  479. // +---------------------------------------------------------------------------+
  480. // | 戻値 nomal:
  481. // +---------------------------------------------------------------------------+
  482. //update20100420
  483. {
  484. global $_TABLES;
  485. $rt=DB_delete($tbl,"id",$id);
  486. if (is_array($fldary)){
  487. for ($i = 1; $i <= count($fldary); $i++) {
  488. $val=current($fldary);
  489. $sql="INSERT INTO {$tbl} (";
  490. $sql.="id, {$fld}";
  491. $sql.=") VALUES (";
  492. $sql.="{$id}, {$val}";
  493. $sql.=")";
  494. DB_query($sql);
  495. next($fldary);
  496. }
  497. }
  498. return ;
  499. }
  500. function DATABOX_savecategorydatas(
  501. $id
  502. ,$fldary
  503. ,$pi_name=""
  504. ,$mydata=""
  505. )
  506. // +---------------------------------------------------------------------------+
  507. // | 機能 複数データ書込(カテゴリ)
  508. // | 書式 DATABOX_savecategorydatas($id,$category,'databox','mydata')
  509. // +---------------------------------------------------------------------------+
  510. // | 引数 $id:
  511. // | 引数 $fldary:データ配列
  512. // | 引数 $pi_name: 'databox' 'userbox' 'formbox'
  513. // +---------------------------------------------------------------------------+
  514. // | 戻値 nomal: |
  515. // +---------------------------------------------------------------------------+
  516. //update20100824
  517. {
  518. global $_TABLES;
  519. if ($pi_name==""){
  520. $table_def_category=$_TABLES['DATABOX_def_category'];
  521. $table_category=$_TABLES['DATABOX_category'];
  522. }else{
  523. $table_def_category=$_TABLES[strtoupper($pi_name).'_def_category'];
  524. $table_category=$_TABLES[strtoupper($pi_name).'_category'];
  525. }
  526. if ($mydata==""){
  527. $rt=DB_delete($table_category,"id",$id);
  528. }else{
  529. $categories=COM_applyFilter($_POST['categories']);
  530. if ($categories=="" ){
  531. }else{
  532. $categories=str_replace("|", ',', $categories);
  533. $sql="DELETE FROM {$table_category} WHERE ";
  534. $sql .=" id = ".$id ;
  535. $sql .=" AND category_id IN (".$categories.")";
  536. DB_query($sql);
  537. }
  538. }
  539. if (is_array($fldary)){
  540. for ($i = 1; $i <= count($fldary); $i++) {
  541. $val=current($fldary);
  542. $sql="INSERT INTO {$table_category} (".LB;
  543. $sql.="id, category_id".LB;
  544. $sql.=") VALUES (".LB;
  545. $sql.="{$id}, {$val}".LB;
  546. $sql.=")".LB;
  547. DB_query($sql);
  548. /////parent_id が0になるまでinsert
  549. $parent_id=DB_getItem( $table_def_category ,"parent_id","category_id={$val}");
  550. while ($parent_id<>0) {
  551. $category_id=$parent_id;
  552. $seq=DB_getItem( $table_category ,"seq","id={$id} AND category_id={$category_id} ");
  553. if (is_null($seq)) {
  554. $sql="INSERT INTO {$table_category} (".LB;
  555. $sql.="id, category_id".LB;
  556. $sql.=") VALUES (".LB;
  557. $sql.="{$id}, {$category_id}".LB;
  558. $sql.=")".LB;
  559. DB_query($sql);
  560. }
  561. $parent_id=DB_getItem( $table_def_category ,"parent_id","category_id={$category_id}");
  562. }
  563. /////
  564. next($fldary);
  565. }
  566. }
  567. return ;
  568. }
  569. //==============================================================================
  570. function DATABOX_chkuser(
  571. $group_id
  572. ,$owner_id
  573. ,$adminrights="databox.admin"
  574. )
  575. // +---------------------------------------------------------------------------+
  576. // | 機能 ユーザチェック
  577. // | 書式 $chk_user=DATABOX_chkuser($group_id,$owner_id,"databox.admin")
  578. // +---------------------------------------------------------------------------+
  579. // | 引数 $group_id
  580. // | 引数 $owner_id
  581. // | 引数 $adminrights databox.admin
  582. // +---------------------------------------------------------------------------+
  583. // | 戻値
  584. // | 0 guest
  585. // | 10 guest and allusers
  586. // | 1000 user
  587. // | 1010 group (owner 含む)
  588. // | 1011 owner
  589. // | 1100 admin
  590. // | 1110 group and admin
  591. // | 1101 owner and admin
  592. // | 1111 group owner and admin
  593. // +---------------------------------------------------------------------------+
  594. //update20101004 group_id
  595. {
  596. global $_USER;
  597. $chk_user=0;
  598. if (isset($_USER['uid']) && $_USER['uid'] > 1) {
  599. $chk_user=1000;//ログインユーザ
  600. }
  601. if ( SEC_hasRights($adminrights)) {
  602. $chk_user=$chk_user+100;//admin
  603. }
  604. //group に属している人
  605. $usergroups=SEC_getUserGroups();
  606. if ( in_array($group_id, $usergroups)){
  607. $chk_user=$chk_user+10;//group
  608. }
  609. if ($owner_id===$_USER['uid']){
  610. $chk_user=$chk_user+1;//owner
  611. }
  612. return $chk_user;
  613. }
  614. function DATABOX_getadditiondef(
  615. $pi_name=""
  616. )
  617. // +---------------------------------------------------------------------------+
  618. // | 機能 追加項目定義読込
  619. // | 書式 DATABOX_getadditiondef($pi_name)
  620. // +---------------------------------------------------------------------------+
  621. // | 引数 $pi_name: 'databox' 'userbox' 'formbox'
  622. // +---------------------------------------------------------------------------+
  623. // | 戻値 nomal:追加項目定義
  624. // +---------------------------------------------------------------------------+
  625. {
  626. global $_TABLES;
  627. global $_CONF;
  628. if ($pi_name==""){
  629. $table=$_TABLES['DATABOX_def_field'];
  630. $table2=$_TABLES['DATABOX_mst'];
  631. }else{
  632. $table=$_TABLES[strtoupper($pi_name).'_def_field'];
  633. $table2=$_TABLES[strtoupper($pi_name).'_mst'];
  634. }
  635. $rt=array();
  636. $fieldgroupno_old="";
  637. $sql="SELECT ";
  638. $sql.= " field_id ";
  639. $sql.= ",name ";
  640. $sql.= ",description";
  641. $sql.= ",type";
  642. //$sql.= ",fieldgroup_id AS group_id";
  643. $sql.= ",selection";
  644. $sql.= ",selectlist";
  645. $sql.= ",checkrequried";
  646. $sql.= ",size";
  647. $sql.= ",maxlength";
  648. $sql.= ",rows";
  649. $sql.= ",br";
  650. $sql.= ",templatesetvar";
  651. $sql.= ",allow_display";
  652. $sql.= ",allow_edit";
  653. $sql.= ",textcheck";
  654. $sql.= ",textconv";
  655. $sql.= ",searchtarget";
  656. $sql.= ",initial_value";
  657. $sql.= ",range_start";
  658. $sql.= ",range_end";
  659. $sql.= ",dfid";
  660. $sql.= ",description2";
  661. $sql.= ",fieldgroupno";
  662. $sql.=" FROM";
  663. $sql.=" {$table} AS m";
  664. $sql.= " ORDER BY orderno,field_id";
  665. $result = DB_query ($sql);
  666. $numrows = DB_numRows ($result);
  667. for ($i = 1; $i <= $numrows; $i++) {
  668. $A = DB_fetchArray ($result);
  669. $field_id = COM_stripslashes($A['field_id']);
  670. $rt[$field_id]['name'] = COM_stripslashes($A['name']);
  671. $rt[$field_id]['checkrequried'] = COM_stripslashes($A['checkrequried']);
  672. $rt[$field_id]['description'] = COM_stripslashes($A['description']);
  673. $rt[$field_id]['allow_display'] = COM_stripslashes($A['allow_display']);
  674. $rt[$field_id]['allow_edit'] = COM_stripslashes($A['allow_edit']);
  675. $rt[$field_id]['textcheck'] = COM_stripslashes($A['textcheck']);
  676. $rt[$field_id]['textconv'] = COM_stripslashes($A['textconv']);
  677. $rt[$field_id]['searchtarget'] = COM_stripslashes($A['searchtarget']);
  678. $rt[$field_id]['type'] = COM_stripslashes($A['type']);
  679. //$rt[$field_id]['group_id'] = COM_stripslashes($A['group_id']);
  680. $rt[$field_id]['selection'] = COM_stripslashes($A['selection']);
  681. $rt[$field_id]['size'] = COM_stripslashes($A['size']);
  682. if ($rt[$field_id]['size']==0){
  683. $rt[$field_id]['size']=60;
  684. }
  685. $rt[$field_id]['maxlength'] = COM_stripslashes($A['maxlength']);
  686. if ($rt[$field_id]['maxlength']==0){
  687. $rt[$field_id]['maxlength']=160;
  688. }
  689. $rt[$field_id]['rows'] = COM_stripslashes($A['rows']);
  690. if ($rt[$field_id]['rows']==0){
  691. $rt[$field_id]['rows']=2;
  692. }
  693. $rt[$field_id]['br'] = COM_stripslashes($A['br']);
  694. $rt[$field_id]['selectlist'] = COM_stripslashes($A['selectlist']);
  695. $rt[$field_id]['templatesetvar'] = COM_stripslashes($A['templatesetvar']);
  696. $selection= COM_stripslashes($A['selection']);
  697. $rt[$field_id]['selectionary']=DATABOX_getselectionary($selection);
  698. $rt[$field_id]['initial_value']= COM_stripslashes($A['initial_value']);
  699. $rt[$field_id]['range_start']= COM_stripslashes($A['range_start']);
  700. $rt[$field_id]['range_end']= COM_stripslashes($A['range_end']);
  701. $dfid= COM_stripslashes($A['dfid']);
  702. $format = DB_getItem($_TABLES['dateformats'], "format", "dfid = $dfid");
  703. if( empty( $format )) {
  704. $rt[$field_id]['format'] = $_CONF['date'];
  705. }else{
  706. $rt[$field_id]['format'] = $format;
  707. }
  708. $rt[$field_id]['description2']= COM_stripslashes($A['description2']);
  709. $fieldgroupno=COM_stripslashes($A['fieldgroupno']);
  710. if ($fieldgroupno_old==$fieldgroupno){
  711. }else{
  712. $fieldgroup_name=DB_getItem($table2,"value","kind='fieldgroup' AND no=".$fieldgroupno);
  713. $fieldgroupno_old=$fieldgroupno;
  714. }
  715. $rt[$field_id]['fieldgroup_name']=$fieldgroup_name;
  716. $rt[$field_id]['fieldgroupno']= $fieldgroupno;
  717. }
  718. return $rt;
  719. }
  720. function DATABOX_getselectionary(
  721. $selection
  722. )
  723. {
  724. $selectionary=array();
  725. $ary=array();
  726. $ary=split("\r" , $selection);
  727. $j=0;
  728. for ($ii = 0; $ii < count($ary); $ii++) {
  729. if ($ary[$ii]<>""){
  730. $selectionary[$j]=$ary[$ii];
  731. $j=$j+1;
  732. }
  733. }
  734. return $selectionary;
  735. }
  736. // +---------------------------------------------------------------------------+
  737. // | 機能 検索用引数作成
  738. // | 書式 DATABOX_getadditionsearchdef($pi_name)
  739. // +---------------------------------------------------------------------------+
  740. // | 引数 $pi_name: 'databox' 'userbox' 'formbox'
  741. // +---------------------------------------------------------------------------+
  742. // | 戻値 配列
  743. // | $rt["sql1"]: ",{$_TABLES['DATABOX_addition']} AS ad1"
  744. // | $rt["sql2"]: " AND t1.id=ad1.id AND ad1.field_id=1 "
  745. // | $rt["columns"][]: 'ad1.value '
  746. // +---------------------------------------------------------------------------+
  747. function DATABOX_getadditionsearchdef(
  748. $pi_name=""
  749. )
  750. {
  751. global $_TABLES;
  752. $box_conf="_".strtoupper($pi_name)."_CONF";
  753. global $$box_conf;
  754. $box_conf=$$box_conf;
  755. $table_def_field=$_TABLES[strtoupper($pi_name).'_def_field'];
  756. $table_addition=$_TABLES[strtoupper($pi_name).'_addition'];
  757. if ($box_conf['additionsearch']==0){
  758. return;
  759. }
  760. $lmt=$box_conf['additionsearch'];
  761. $retval=array();
  762. $rt=array();
  763. $sql3="";
  764. $columns=array();
  765. $sql=LB;
  766. $sql.="SELECT ";
  767. $sql.= " field_id ";
  768. $sql.=" FROM";
  769. $sql.=" {$table_def_field} AS m";
  770. // 表示する項目のみ
  771. $sql.=" WHERE";
  772. $sql.=" allow_display='0'";
  773. //0: 一行テキストフィールド
  774. //1: 複数行テキストフィールド
  775. //20:HTML 10:TinyMCE 19:CKEditor
  776. //15:数値 21:通貨
  777. $sql.=" AND type IN (0,1,10,19,20,15,21)";
  778. //検索対象にする=はい
  779. $sql.=" AND searchtarget='1'";
  780. $sql.=" ORDER BY orderno,field_id";
  781. $sql.=" LIMIT 0 ,".$lmt;
  782. $result = DB_query ($sql);
  783. $numrows = DB_numRows ($result);
  784. for ($i = 1; $i <= $numrows; $i++) {
  785. $A = DB_fetchArray ($result);
  786. $field_id = COM_stripslashes($A['field_id']);
  787. $type = COM_stripslashes($A['type']);
  788. $selection= COM_stripslashes($A['selection']);
  789. $selectionary=DATABOX_getselectionary($selection);
  790. $columns[]= "ad{$field_id}.value ";
  791. $sql3 .= " JOIN {$table_addition} AS ad{$field_id}";
  792. $sql3 .= " ON t1.id=ad{$field_id}.id ";
  793. $sql3 .= " AND ad{$field_id}.field_id={$field_id} ".LB;
  794. }
  795. $rt["sql3"]=$sql3;
  796. $rt["columns"]=$columns;
  797. return $rt;
  798. }
  799. function DATABOX_getadditiondatas(
  800. $id
  801. ,$pi_name=""
  802. )
  803. // +---------------------------------------------------------------------------+
  804. // | 機能 追加項目読込
  805. // | 書式 DATABOX_getadditiondatas($id)
  806. // | $array=DATABOX_getaddtuindatas($id);
  807. // +---------------------------------------------------------------------------+
  808. // | 引数 $id:
  809. // | 引数 $pi_name:plugin name 'databox' 'userbox' 'formbox'
  810. // +---------------------------------------------------------------------------+
  811. // | 戻値 nomal:追加項目リスト |
  812. // +---------------------------------------------------------------------------+
  813. {
  814. global $_TABLES;
  815. if ($pi_name==""){
  816. $table_addition=$_TABLES['DATABOX_addition'];
  817. $table_def_field=$_TABLES['DATABOX_def_field'];
  818. }else{
  819. $table_addition=$_TABLES[strtoupper($pi_name).'_addition'];
  820. $table_def_field=$_TABLES[strtoupper($pi_name).'_def_field'];
  821. }
  822. $rt=array();
  823. $sql="SELECT ";
  824. $sql.=" m.field_id";
  825. $sql.=" ,m.fieldgroupno";
  826. if ($id==0){
  827. $sql.=",initial_value AS value ";
  828. }else{
  829. $sql.=", ( SELECT VALUE ";
  830. $sql.=" FROM";
  831. $sql.=" {$table_addition} AS t";
  832. $sql.=" where";
  833. $sql.=" t.id={$id}";
  834. $sql.=" AND t.field_id=m.field_id";
  835. $sql.=" ) AS value ";
  836. }
  837. $sql.=" FROM";
  838. $sql.=" {$table_def_field} AS m";
  839. $sql.=" order by m.fieldgroupno,m.orderno ,m.field_id";
  840. $result = DB_query ($sql);
  841. $numrows = DB_numRows ($result);
  842. for ($i = 1; $i <= $numrows; $i++) {
  843. $A = DB_fetchArray ($result);
  844. $field_id=$A['field_id'];
  845. $value=$A['value'];
  846. $rt[$field_id]=COM_stripslashes($value);
  847. }
  848. return $rt;
  849. }
  850. function DATABOX_getaddtionfieldsEdit(
  851. $fields
  852. ,$addition_def
  853. ,$templates
  854. ,$chk_user
  855. ,$pi_name=""
  856. ,$fields_fnm=""
  857. ,$fields_del=""
  858. ,$fieldset_id=0
  859. ,$fields_date=""
  860. )
  861. // +---------------------------------------------------------------------------+
  862. // | 機能 追加項目入力用HTML作成
  863. // | 書式 DATABOX_getaddtionfieldsEdit
  864. // ($additionfields,$addition_def,$templates,$chk_user)
  865. // +---------------------------------------------------------------------------+
  866. // | 引数 $fields:
  867. // | 引数 $addition_def:
  868. // | 引数 $templates:
  869. // | 引数 $chk_user:
  870. // | 引数 $pi_name:plugin name 'databox' 'userbox' 'formbox'
  871. // | 引数 $fields_fnm:
  872. // | 引数 $fields_del:
  873. // | 引数 $fieldset_id:
  874. // +---------------------------------------------------------------------------+
  875. // | 戻値 nomal:追加項目入力用HTML  |
  876. // +---------------------------------------------------------------------------+
  877. // 20101206 日付
  878. {
  879. global $_TABLES;
  880. global $_SCRIPTS;
  881. global $_CONF;
  882. global $MESSAGE;
  883. if ($pi_name==""){
  884. $pi_name="databox";
  885. }
  886. $lang_admin_x="LANG_".strtoupper($pi_name)."_ADMIN";
  887. $lang_admin="LANG_".strtoupper($pi_name)."_ADMIN";
  888. $lang_noyes="LANG_".strtoupper($pi_name)."_NOYES";
  889. $table_def_field=$_TABLES[strtoupper($pi_name).'_def_field'];
  890. $box_conf="_".strtoupper($pi_name)."_CONF";
  891. global $$box_conf;
  892. $box_conf=$$box_conf;
  893. global $$lang_admin;
  894. global $$lang_noyes;
  895. $lang_admin=$$lang_admin;
  896. $lang_noyes=$$lang_noyes;
  897. $langCode = COM_getLangIso639Code();
  898. $toolTip = $MESSAGE[118];
  899. $imgUrl = $_CONF['site_url'] . '/images/calendar.png';
  900. $fieldsetfields=DATABOX_getfields($pi_name, $fieldset_id);
  901. $retval = '';
  902. if (is_array($fields)){
  903. $S = $fields;
  904. }else{
  905. if( !empty( $selected )) {
  906. $S = explode( ' ', $fields );
  907. }else {
  908. $S = array();
  909. }
  910. }
  911. $fieldgroup_old="";
  912. foreach( $S as $fid => $fvalue ){
  913. $name=$addition_def[$fid]['name'];
  914. $checkrequried=$addition_def[$fid]['checkrequried'];
  915. $type=$addition_def[$fid]['type'];
  916. $selectionary=$addition_def[$fid]['selectionary'];
  917. $selectlist=$addition_def[$fid]['selectlist'];
  918. $size=$addition_def[$fid]['size'];
  919. $maxlength=$addition_def[$fid]['maxlength'];
  920. $rows=$addition_def[$fid]['rows'];
  921. $br=$addition_def[$fid]['br'];
  922. $templatesetvar=$addition_def[$fid]['templatesetvar'];
  923. $description=$addition_def[$fid]['description'];
  924. $description2=$addition_def[$fid]['description2'];
  925. $fieldgroup_name=$addition_def[$fid]['fieldgroup_name'];
  926. $chk=false;
  927. $disabled="disabled";
  928. if (in_array($fid,$fieldsetfields )) {
  929. if ($chk_user===9999){
  930. $chk=true;
  931. $disabled="";
  932. }else{
  933. //編集可能
  934. if ($addition_def[$fid]['allow_edit']==='0') {
  935. $chk=true;
  936. $disabled="";
  937. //グループとadmin権のある人のみ表示
  938. }else if ($addition_def[$fid]['allow_edit']==='2'){
  939. if ($chk_user>=1010) {
  940. $chk=true;
  941. $disabled="";
  942. }
  943. //所有者とadmin権のある人のみ
  944. }else if ($addition_def[$fid]['allow_edit']==='3'){
  945. if ($chk_user>=1011) {
  946. $chk=true;
  947. $disabled="";
  948. }
  949. //編集不可表示のみ
  950. }else if ($addition_def[$fid]['allow_edit']==='4'){
  951. $chk=true;
  952. }
  953. }
  954. }
  955. if ($chk) {
  956. $fieldhtml="";
  957. switch ($type) {
  958. case 12:// 図
  959. $fvalue_fnm=$fields_fnm[$fid];
  960. $fvalue_del=$fields_del[$fid];
  961. $fieldhtml .=DATABOX_figurehtml12
  962. ($fid,$fvalue,$fvalue_del,$size,$maxlength);
  963. break;
  964. case 11:// 図
  965. $fvalue_fnm=$fields_fnm[$fid];
  966. $fvalue_del=$fields_del[$fid];
  967. $fieldhtml .=DATABOX_figurehtml
  968. ($fid,$fvalue,$fvalue_del);
  969. break;
  970. case 13:// 添付ファイル
  971. $fvalue_fnm=$fields_fnm[$fid];
  972. $fvalue_del=$fields_del[$fid];
  973. $fieldhtml .=DATABOX_filehtml
  974. ($pi_name,$fid,$fvalue,$fvalue_del);
  975. break;
  976. case 1:// 複数行テキストフィールド(HTML OK)
  977. case 10:// 複数行テキストフィールド(HTML NG)
  978. case 20:// 複数行テキストフィールド(HTML OK TinyMCE)//@@@@@
  979. case 19:// 複数行テキストフィールド(HTML OK CKEditor)//@@@@@
  980. if ($disabled===""){
  981. $cntname="afieldcnt".$fid;
  982. $fieldhtml .= "<textarea ";
  983. $fieldhtml .= " name=\"afield[".$fid."]\" ";
  984. $fieldhtml .= " style=\"width:95%\"";
  985. $fieldhtml .= " rows=\"".$rows."\"";
  986. $fieldhtml .= " id=\"DATABOX_afield".$fid."\"";
  987. $fieldhtml .= " ".$disabled." ";
  988. $fieldhtml .= " onKeyup=\"var n=".$maxlength;
  989. $fieldhtml .="-this.value.length;var ";
  990. $fieldhtml .="s=document.getElementById";
  991. $fieldhtml .="('".$cntname."');s.innerHTML='('+n+')';\"";
  992. if ($type==20){
  993. $fieldhtml .= " class=\"tinymce_enabled\"";
  994. }
  995. if ($type==19){
  996. $fieldhtml .= " class=\"wide\"";
  997. }
  998. $fieldhtml .= ">";
  999. $fieldhtml .= $fvalue;
  1000. $fieldhtml .= "</textarea>";
  1001. $fieldhtml .="<br ".XHTML."><strong>";
  1002. $fieldhtml .="<span id='".$cntname."'></span></strong>";
  1003. }else{
  1004. $fieldhtml .=$fvalue;
  1005. }
  1006. break;
  1007. case 2://いいえ/はい
  1008. if ($disabled===""){
  1009. $fieldhtml=DATABOX_getradiolist
  1010. ($lang_noyes,"afield[".$fid."]",$fvalue,$br ,$disabled);
  1011. }else{
  1012. $fieldhtml= $lang_noyes[$fvalue];
  1013. }
  1014. break;
  1015. case 7://オプションリスト(選択肢)
  1016. case 14://マルチセレクトリスト(選択肢)
  1017. if ($disabled===""){
  1018. $fieldhtml=DATABOX_getoptionlistary($selectionary,"afield[".$fid."]",$fvalue,$pi_name, $disabled,$type,$size);
  1019. }else{
  1020. $selectionary[$fvalue];
  1021. }
  1022. break;
  1023. case 24://チェックボックス(選択肢)
  1024. if ($disabled===""){
  1025. $fieldhtml=DATABOX_getcheckboxary($selectionary,"afield[".$fid."]",$fvalue,$pi_name, $disabled,$type,$size);
  1026. }else{
  1027. $selectionary[$fvalue];
  1028. }
  1029. break;
  1030. case 25://チェックボックス(マスター)
  1031. if ($disabled===""){
  1032. $mstary=DATABOX_getAry("selectlist_mst",0,$selectlist,$pi_name);
  1033. $fieldhtml=DATABOX_getcheckboxary($mstary,"afield[".$fid."]",$fvalue,$pi_name, $disabled,$type,$size);
  1034. }else{
  1035. $selectionary[$fvalue];
  1036. }
  1037. break;
  1038. case 9://オプションリスト(マスター)
  1039. if ($disabled===""){
  1040. $fieldhtml=DATABOX_getoptionlist("selectlist_mst",$fvalue,0,$pi_name,"",0,$selectlist,"afield[".$fid."]");
  1041. }else{
  1042. $selectionary[$fvalue];
  1043. }
  1044. break;
  1045. case 8://ラジオボタンリスト(選択肢)
  1046. if ($disabled===""){
  1047. $fieldhtml=DATABOX_getradiolist ($selectionary,"afield[".$fid."]",$fvalue,$br,$disabled,$type);
  1048. }else{
  1049. $selectionary[$fvalue];
  1050. }
  1051. break;
  1052. case 16://ラジオボタンリスト(マスター)//@@@@@
  1053. if ($disabled===""){
  1054. $mstary=DATABOX_getAry("selectlist_mst",0,$selectlist,$pi_name);
  1055. $fieldhtml=DATABOX_getradiolist ($mstary,"afield[".$fid."]",$fvalue,$br,$disabled,$type);
  1056. }else{
  1057. $selectionary[$fvalue];
  1058. }
  1059. break;
  1060. case 18://マルチセレクトリスト(マスター)//@@@@@
  1061. if ($disabled===""){
  1062. $mstary=DATABOX_getAry("selectlist_mst",0,$selectlist,$pi_name);
  1063. $fieldhtml=DATABOX_getoptionlistary($mstary,"afield[".$fid."]",$fvalue,$pi_name, $disabled,$type,$size);
  1064. }else{
  1065. $selectionary[$fvalue];
  1066. }
  1067. break;
  1068. case 3://日付(date picker対応)
  1069. if ($disabled===""){
  1070. //$filedname="afield[".$fid."]";
  1071. $filedname="afield".$fid;
  1072. $_SCRIPTS->setJavaScript(
  1073. "jQuery(function () {"
  1074. . " geeklog.datepicker.set('{$filedname}', '{$langCode}', '{$toolTip}', '{$imgUrl}');"
  1075. . "});", TRUE, TRUE
  1076. );
  1077. if (is_array($fields_date)){
  1078. $fieldhtml.=DATABOX_datetimeedit_R($fields_date[$fid],$lang_admin_x,$filedname);
  1079. }else{
  1080. $fieldhtml.=DATABOX_datetimeedit($fvalue,$lang_admin_x,$filedname,"date");
  1081. }
  1082. $wk = " <input ";
  1083. $wk .= " type=\"hidden\"";
  1084. $wk .= " name=\"afield[".$fid."]\" ";
  1085. $wk .= " value=\"".$fvalue."\"";
  1086. $wk .= " ".XHTML.">";
  1087. $fieldhtml.=$wk;
  1088. }else{
  1089. $fieldhtml .=$fvalue;
  1090. }
  1091. break;
  1092. case 4://日時(datetime picker対応)
  1093. if ($disabled===""){
  1094. //$filedname="afield[".$fid."]";
  1095. $filedname="afield".$fid;
  1096. $_SCRIPTS->setJavaScript(
  1097. "jQuery(function () {"
  1098. . " geeklog.hour_mode = {$_CONF['hour_mode']};"
  1099. . " geeklog.datetimepicker.set('{$filedname}', '{$langCode}', '{$toolTip}', '{$imgUrl}');"
  1100. . "});", TRUE, TRUE
  1101. );
  1102. if (is_array($fields_date)){
  1103. $fieldhtml.=DATABOX_datetimeedit_R($fields_date[$fid],$lang_admin_x,$filedname);
  1104. }else{
  1105. $fieldhtml.=DATABOX_datetimeedit($fvalue,$lang_admin_x,$filedname,"datetime");
  1106. }
  1107. $wk = " <input ";
  1108. $wk .= " type=\"hidden\"";
  1109. $wk .= " name=\"afield[".$fid."]\" ";
  1110. $wk .= " value=\"".$fvalue."\"";
  1111. $wk .= " ".XHTML.">";
  1112. $fieldhtml.=$wk;
  1113. }else{
  1114. $fieldhtml .=$fvalue;
  1115. }
  1116. break;
  1117. case 26://時刻(UI time picker対応)
  1118. if ($disabled===""){
  1119. $fvalue_time=DATABOX_getTimeformat($fvalue);
  1120. $filedname="afield".$fid;
  1121. $wk = " <input ";
  1122. $wk .= " type=\"hidden\"";
  1123. $wk .= " name=\"afield[".$fid."]\" ";
  1124. $wk .= " value=\"".$fvalue."\"";
  1125. $wk .= " ".XHTML.">";
  1126. $fieldhtml.=$wk;
  1127. $fieldhtml .= " <input ";
  1128. $fieldhtml .= " data-uk-timepicker=\"{format:'".$_CONF['hour_mode']."h'";
  1129. if ($addition_def[$fid]['range_start']==""){
  1130. }else{
  1131. $fieldhtml .= ",start:".$addition_def[$fid]['range_start'] ;
  1132. }
  1133. if ($addition_def[$fid]['range_end']==""){
  1134. }else{
  1135. $fieldhtml .= ",end:".$addition_def[$fid]['range_end'] ;
  1136. }
  1137. $fieldhtml .= " }\"";
  1138. $fieldhtml .= " class=\"uk-form-width-small\"";
  1139. $fieldhtml .= " type=\"text\"";
  1140. $fieldhtml .= " id=\"afield".$fid."\"";
  1141. $fieldhtml .= " size=\"".$size."\"";
  1142. $fieldhtml .= " maxlength=\"".$maxlength."\" ";
  1143. $fieldhtml .= " name=\"afield[".$fid."]\" ";
  1144. $fieldhtml .= " style=\"max-width:95%\"";
  1145. $fieldhtml .= " value=\"". $fvalue_time."\"";
  1146. $fieldhtml .= " ".XHTML.">";
  1147. }else{
  1148. $fieldhtml .=$fvalue;
  1149. }
  1150. break;
  1151. case 22://日付
  1152. if ($disabled===""){
  1153. if ($fvalue=="") {
  1154. $fvalue_date="";
  1155. }else{
  1156. $fvalue_date=date( $box_conf['dateformat'], $fvalue );
  1157. }
  1158. $filedname="afield".$fid;
  1159. $_SCRIPTS->setJavaScript(
  1160. "$(function() {
  1161. $( \"#afield".$fid."\" ).datepicker();
  1162. });"
  1163. , TRUE, TRUE
  1164. );
  1165. $wk = " <input ";
  1166. $wk .= " type=\"hidden\"";
  1167. $wk .= " name=\"afield[".$fid."]\" ";
  1168. $wk .= " value=\"".$fvalue."\"";
  1169. $wk .= " ".XHTML.">";
  1170. $fieldhtml.=$wk;
  1171. $fieldhtml .= " <input ";
  1172. $fieldhtml .= " type=\"text\"";
  1173. $fieldhtml .= " id=\"afield".$fid."\"";
  1174. $fieldhtml .= " size=\"".$size."\"";
  1175. $fieldhtml .= " maxlength=\"".$maxlength."\" ";
  1176. $fieldhtml .= " name=\"afield[".$fid."]\" ";
  1177. $fieldhtml .= " style=\"max-width:95%\"";
  1178. $fieldhtml .= " value=\"".$fvalue_date."\"";
  1179. $fieldhtml .= " ".XHTML.">";
  1180. }else{
  1181. $fieldhtml .=$fvalue;
  1182. }
  1183. break;
  1184. case 23://日付
  1185. if ($disabled===""){
  1186. if ($fvalue=="") {
  1187. $fvalue_date="";
  1188. }else{
  1189. $fvalue_date=date( $box_conf['dateformat'], $fvalue );
  1190. }
  1191. $filedname="afield".$fid;
  1192. $wk = " <input ";
  1193. $wk .= " type=\"hidden\"";
  1194. $wk .= " name=\"afield[".$fid."]\" ";
  1195. $wk .= " value=\"".$fvalue."\"";
  1196. $wk .= " ".XHTML.">";
  1197. $fieldhtml.=$wk;
  1198. $fieldhtml .= " <input ";
  1199. $fieldhtml .= " data-uk-datepicker=\"{format:'YYYY/MM/DD'}\"";
  1200. $fieldhtml .= " type=\"text\"";
  1201. $fieldhtml .= " id=\"afield".$fid."\"";
  1202. $fieldhtml .= " size=\"".$size."\"";
  1203. $fieldhtml .= " maxlength=\"".$maxlength."\" ";
  1204. $fieldhtml .= " name=\"afield[".$fid."]\" ";
  1205. $fieldhtml .= " style=\"max-width:95%\"";
  1206. $fieldhtml .= " value=\"". $fvalue_date."\"";
  1207. $fieldhtml .= " ".XHTML.">";
  1208. }else{
  1209. $fieldhtml .=$fvalue;
  1210. }
  1211. break;
  1212. case 17://フラグ
  1213. if ($disabled===""){
  1214. $wk =" <input ";
  1215. $wk .= " type=\"checkbox\"";
  1216. $wk .= " name=\"afield[".$fid."]\" ";
  1217. $wk .= " value=\"1\"";
  1218. if ($fvalue==1) {
  1219. $wk .= " checked=checked";
  1220. }
  1221. $wk .= " ".XHTML.">";
  1222. $fieldhtml=$wk;
  1223. }else{
  1224. $fieldhtml= $fvalue;
  1225. }
  1226. break;
  1227. case 5://メールアドレス';
  1228. case 6://url';
  1229. case 0:// 一行テキストフィールド
  1230. default:
  1231. if ($disabled===""){
  1232. $fieldhtml .= " <input ";
  1233. $fieldhtml .= " type=\"text\"";
  1234. $fieldhtml .= " size=\"".$size."\"";
  1235. $fieldhtml .= " maxlength=\"".$maxlength."\" ";
  1236. $fieldhtml .= " name=\"afield[".$fid."]\" ";
  1237. $fieldhtml .= " style=\"max-width:95%\"";
  1238. $fieldhtml .= " value=\"".$fvalue."\"";
  1239. $fieldhtml .= " ".XHTML.">";
  1240. }else{
  1241. $fieldhtml .=$fvalue;
  1242. }
  1243. }
  1244. if ($checkrequried==1){//必須
  1245. $must= $lang_admin['must'];
  1246. }else{
  1247. $must="";
  1248. }
  1249. $templates->set_var('lang_must_additionfield', $must);
  1250. $templates->set_var('additionfield_name', $name);
  1251. $templates->set_var('additionfield_templatesetvar', "&#123;".$templatesetvar."&#125;");
  1252. $addisionfields .= $fieldhtml;
  1253. $templates->set_var('additionfield_value', $fieldhtml);
  1254. $templates->set_var('additionfield_description', $description);
  1255. $templates->set_var('additionfield_description2', $description2);
  1256. $templates->set_var('fieldgroup_name', $fieldgroup_name);
  1257. if ($fieldgroup_old==$fieldgroup_name){
  1258. $templates->set_var('fieldgroup', "");
  1259. }else{
  1260. $templates->set_var('fieldgroup', $fieldgroup_name);
  1261. $fieldgroup_old=$fieldgroup_name;
  1262. }
  1263. $templates->set_var('additionfield'.$fid, $fieldhtml);
  1264. $templates->set_var($templatesetvar, $fieldhtml);
  1265. //=====
  1266. $templates->parse ('col_var', 'col', true);
  1267. $templates->parse ('additionfields', 'row', true);
  1268. $templates->set_var ('col_var', '');
  1269. }
  1270. }
  1271. return $retval;
  1272. }
  1273. //
  1274. function DATABOX_figurehtml(
  1275. $fid
  1276. ,$fvalue
  1277. ,$fvalue_del
  1278. )
  1279. {
  1280. global $LANG04;
  1281. //
  1282. $retval .= " <input ";
  1283. $retval .= " type=\"hidden\"";
  1284. $retval .= " name=\"afield[".$fid."]\" ";
  1285. $retval .= " value=\"".$fvalue."\"";
  1286. $retval .= " ".XHTML.">".LB;
  1287. $retval .="<input type=\"file\" dir=\"ltr\"";
  1288. $retval .= " id=\"afield_fnm[".$fid."]\" ";
  1289. $retval .= " name=\"afield_fnm[".$fid."]\" ";
  1290. // $retval .= " value=\"".$fvalue_fnm."\"";
  1291. $retval .="size=\"30\"";
  1292. $retval .= " ".XHTML.">".LB;
  1293. if ($fvalue<>""){
  1294. $retval .= '<br' . XHTML . '>' ;
  1295. $retval .= '<br' . XHTML . '>' ;
  1296. $retval .="<img src=\"data:image/jpg;base64,";
  1297. $retval .="{$fvalue}\"";
  1298. $retval .="width=100 height=100";
  1299. $retval .=" ".XHTML.">".LB;
  1300. //
  1301. $retval .= '<br' . XHTML . '>' ;
  1302. $retval .= '<br' . XHTML . '>' ;
  1303. $retval .= $LANG04[79];
  1304. $retval .= "<input type=\"checkbox\"";
  1305. $retval .= " name=\"afield_del[".$fid."]\" ";
  1306. if ($fvalue_del){
  1307. $retval .= " checked ";
  1308. }
  1309. $retval .= " ".XHTML.">".LB;
  1310. }
  1311. // $photo_x = USER_getPhoto ($uid, $photo, $email, -1);
  1312. return $retval;
  1313. }
  1314. function DATABOX_filehtml(
  1315. $pi_name
  1316. ,$fid
  1317. ,$fvalue
  1318. ,$fvalue_del
  1319. )
  1320. {
  1321. $lang_box_admin="LANG_".strtoupper($pi_name)."_ADMIN";
  1322. global $$lang_box_admin;
  1323. $lang_box_admin=$$lang_box_admin;
  1324. //
  1325. $retval .= " <input ";
  1326. $retval .= " type=\"hidden\"";
  1327. $retval .= " name=\"afield[".$fid."]\" ";
  1328. $retval .= " value=\"".$fvalue."\"";
  1329. $retval .= " ".XHTML.">".LB;
  1330. $retval .="<input type=\"file\" dir=\"ltr\"";
  1331. $retval .= " id=\"afield_fnm[".$fid."]\" ";
  1332. $retval .= " name=\"afield_fnm[".$fid."]\" ";
  1333. $retval .="size=\"30\"";
  1334. $retval .= " ".XHTML.">".LB;
  1335. if ($fvalue<>""){
  1336. $retval .="{$fvalue}";
  1337. $retval .= '<br' . XHTML . '>' ;
  1338. $retval .= $lang_box_admin['deletemsg_check'];
  1339. $retval .= "<input type=\"checkbox\"";
  1340. $retval .= " name=\"afield_del[".$fid."]\" ";
  1341. if ($fvalue_del){
  1342. $retval .= " checked ";
  1343. }
  1344. $retval .= " ".XHTML.">".LB;
  1345. }
  1346. return $retval;
  1347. }
  1348. function DATABOX_figurehtml12(
  1349. $fid
  1350. ,$fvalue
  1351. ,$fvalue_del
  1352. ,$size
  1353. ,$maxlength
  1354. )
  1355. {
  1356. global $LANG04;
  1357. $a=explode("|",$fvalue);
  1358. //
  1359. $retval .= " <input ";
  1360. $retval .= " type=\"hidden\"";
  1361. $retval .= " name=\"afield[".$fid."]\" ";
  1362. $retval .= " value=\"".$fvalue."\"";
  1363. $retval .= " ".XHTML.">".LB;
  1364. $retval .="<input type=\"file\" dir=\"ltr\"";
  1365. $retval .= " id=\"afield_fnm[".$fid."]\" ";
  1366. $retval .= " name=\"afield_fnm[".$fid."]\" ";
  1367. $retval .="size=\"30\"";
  1368. $retval .= " ".XHTML.">".LB;
  1369. $retval .= "<input ";
  1370. $retval .= " type=\"text\"";
  1371. $retval .= " size=\"".$size."\"";
  1372. $retval .= " maxlength=\"".$maxlength."\" ";
  1373. $retval .= " name=\"afield_alt[".$fid."]\" ";
  1374. $retval .= " style=\"max-width:95%\"";
  1375. $retval .= " value=\"".$a[1]."\"";
  1376. $retval .= " ".XHTML.">";
  1377. if ($fvalue<>""){
  1378. $retval .="{$fvalue}";
  1379. $retval .= '<br' . XHTML . '>' ;
  1380. $retval .= $LANG04[79];
  1381. $retval .= "<input type=\"checkbox\"";
  1382. $retval .= " name=\"afield_del[".$fid."]\" ";
  1383. if ($fvalue_del){
  1384. $retval .= " checked ";
  1385. }
  1386. $retval .= " ".XHTML.">".LB;
  1387. }
  1388. return $retval;
  1389. }
  1390. function DATABOX_imagehtml(
  1391. $name
  1392. ,$fvalue
  1393. ,$fvalue_del
  1394. )
  1395. {
  1396. global $LANG04;
  1397. //
  1398. $retval .= " <input ";
  1399. $retval .= " type=\"hidden\"";
  1400. $retval .= " name=\"".$name."\" ";
  1401. $retval .= " value=\"".$fvalue."\"";
  1402. $retval .= " ".XHTML.">".LB;
  1403. if ($fvalue==""){
  1404. $retval .="<input type=\"file\" dir=\"ltr\"";
  1405. $retval .= " id=\"".$name."\" ";
  1406. $retval .= " name=\"".$name."\" ";
  1407. $retval .="size=\"30\"";
  1408. $retval .= " ".XHTML.">".LB;
  1409. }else{
  1410. $retval .="{$fvalue}";
  1411. $retval .= '<br' . XHTML . '>' ;
  1412. $retval .= $LANG04[79];
  1413. $retval .= "<input type=\"checkbox\"";
  1414. $retval .= " name=\"".$name."_del\" ";
  1415. if ($fvalue_del){
  1416. $retval .= " checked ";
  1417. }
  1418. $retval .= " ".XHTML.">".LB;
  1419. }
  1420. return $retval;
  1421. }
  1422. function DATABOX_getaddtionfieldsText(
  1423. $fields
  1424. ,$addition_def
  1425. ,$chk_user
  1426. ,$pi_name
  1427. ,$fieldset_id
  1428. )
  1429. // +---------------------------------------------------------------------------+
  1430. // | 機能 追加項目TEXT作成
  1431. // | 書式 DATABOX_getaddtionfieldsText
  1432. // | ($additionfields,$addition_def,$chk_user)
  1433. // +---------------------------------------------------------------------------+
  1434. // | 引数 $fields:
  1435. // | 引数 $addition_def:
  1436. // | 引数 $chk_user:
  1437. // | 引数 $pi_name:plugin name 'databox' 'userbox' 'formbox'
  1438. // | 引数 $fieldset_id
  1439. // +---------------------------------------------------------------------------+
  1440. // | 戻値 nomal:追加項目text
  1441. // +---------------------------------------------------------------------------+
  1442. //
  1443. {
  1444. global $_CONF;
  1445. $lang_noyes="LANG_".strtoupper($pi_name)."_NOYES";
  1446. global $$lang_noyes;
  1447. $lang_noyes=$$lang_noyes;
  1448. $lang_box="LANG_".strtoupper($pi_name);
  1449. global $$lang_box;
  1450. $lang_box=$$lang_box;
  1451. $separater=$lang_box['field_separater'];
  1452. $templatesetvar=$addition_def[$fid]['templatesetvar'];
  1453. $retval = '';
  1454. if (is_array($fields)){
  1455. $S = $fields;
  1456. }else{
  1457. if( !empty( $selected )) {
  1458. $S = explode( ' ', $fields );
  1459. }else {
  1460. $S = array();
  1461. }
  1462. }
  1463. foreach( $S as $fid => $fvalue ){
  1464. $name=$addition_def[$fid]['name'];
  1465. $checkrequried=$addition_def[$fid]['checkrequried'];
  1466. $type=$addition_def[$fid]['type'];
  1467. $selectionary=$addition_def[$fid]['selectionary'];
  1468. $selectlist=$addition_def[$fid]['selectlist'];
  1469. $size=$addition_def[$fid]['size'];
  1470. $maxlength=$addition_def[$fid]['maxlength'];
  1471. $rows=$addition_def[$fid]['rows'];
  1472. $br=$addition_def[$fid]['br'];
  1473. $fieldsetfields=DATABOX_getfields($pi_name, $fieldset_id);
  1474. $chk=false;
  1475. $disabled="disabled";
  1476. if ($chk_user===9999){
  1477. $chk=true;
  1478. $disabled="";
  1479. }else{
  1480. //編集可能
  1481. if ($addition_def[$fid]['allow_edit']==='0') {
  1482. $chk=true;
  1483. $disabled="";
  1484. //グループとadmin権のある人のみ表示
  1485. }else if ($addition_def[$fid]['allow_edit']==='2'){
  1486. if ($chk_user>=1010) {
  1487. $chk=true;
  1488. $disabled="";
  1489. }
  1490. //所有者とadmin権のある人のみ
  1491. }else if ($addition_def[$fid]['allow_edit']==='3'){
  1492. if ($chk_user>=1011) {
  1493. $chk=true;
  1494. $disabled="";
  1495. }
  1496. //編集不可表示のみ
  1497. }else if ($addition_def[$fid]['allow_edit']==='4'){
  1498. $chk=true;
  1499. }
  1500. }
  1501. if (in_array($fid,$fieldsetfields )) {
  1502. if ($chk) {
  1503. $retval.=$name.":";
  1504. switch ($type) {
  1505. case 11://図
  1506. $retval .= "";
  1507. break;
  1508. case 2://いいえ/はい
  1509. $retval .= $lang_noyes[$fvalue];
  1510. break;
  1511. case 7://オプションリスト(選択肢)
  1512. case 8://オプションリスト(選択肢)
  1513. $retval .= $selectionary[$fvalue];
  1514. break;
  1515. case 14://マルチセレクトリスト(選択肢)
  1516. case 24://チェックボックス(選択肢)
  1517. $wkary=explode(":",$fvalue);
  1518. $wk="";
  1519. for( $x = 0; $x < sizeof( $wkary ); $x++ ) {
  1520. $wk.=$selectionary[$wkary[$x]].$separater;
  1521. }
  1522. $retval .= rtrim($wk,$separater);
  1523. break;
  1524. case 9://オプションリスト(マスター)
  1525. case 16://ラジオボタンリスト(マスター)
  1526. $mstitems=DATABOX_getMstItems($selectlist,$fvalue,$pi_name);
  1527. $retval .= $mstitems['value'];
  1528. break;
  1529. case 18://マルチセレクトリスト(マスター)
  1530. case 25://チェックボックス(マスター)
  1531. $wkary=explode(":",$fvalue);
  1532. $wk="";
  1533. for( $x = 0; $x < sizeof( $wkary ); $x++ ) {
  1534. $mstitems=DATABOX_getMstItems($selectlist,$wkary[$x],$pi_name);
  1535. $wk.=$mstitems['value'].$separater;
  1536. }
  1537. $retval .= rtrim($wk,$separater);
  1538. break;
  1539. case 4://日時
  1540. $w=COM_getUserDateTimeFormat($fvalue);
  1541. $retval .= $w[0];
  1542. break;
  1543. case 22://日付
  1544. case 23://日付
  1545. case 3://日付
  1546. if ($fvalue<>""){
  1547. $retval .=strftime( $_CONF['shortdate'], $fvalue );
  1548. }
  1549. break;
  1550. case 5://メールアドレス (準備中)';
  1551. case 6://url (準備中)';
  1552. case 0:// 一行テキストフィールド
  1553. case 1:// 複数行テキストフィールド(HTML OK)
  1554. case 10:// 複数行テキストフィールド(HTML NG)
  1555. case 20:// 複数行テキストフィールド(HTML OK TinyMCE)//@@@@@
  1556. case 19:// 複数行テキストフィールド(HTML OK CKEditor)//@@@@@
  1557. default:
  1558. $retval .= $fvalue;
  1559. }
  1560. $retval.=LB;
  1561. }
  1562. }
  1563. }
  1564. return $retval;
  1565. }
  1566. function DATABOX_getaddtionfieldsDisp(
  1567. $fields
  1568. ,$addition_def
  1569. ,$templates
  1570. ,$chk_user
  1571. ,$pi_name
  1572. ,$fieldset_id
  1573. )
  1574. // +---------------------------------------------------------------------------+
  1575. // | 機能 追加項目表示用HTML作成 |
  1576. // | 書式 DATABOX_getaddtionfieldsDisp
  1577. // | ($additionfields,$addition_def,$templates,$chk_user)
  1578. // +---------------------------------------------------------------------------+
  1579. // | 引数 $fields:
  1580. // | 引数 $addition_def:
  1581. // | 引数 $templates:
  1582. // | 引数 $chk_user:
  1583. // | 引数 $pi_name:plugin name 'databox' 'userbox' 'formbox'
  1584. // | 引数 $fieldset_id
  1585. // +---------------------------------------------------------------------------+
  1586. // | 戻値 nomal:追加項目表示用HTML  |
  1587. // +---------------------------------------------------------------------------+
  1588. //update 20101012 $chk_user
  1589. {
  1590. global $_CONF;
  1591. global $_TABLES;
  1592. $lang_noyes="LANG_".strtoupper($pi_name)."_NOYES";
  1593. global $$lang_noyes;
  1594. $lang_noyes=$$lang_noyes;
  1595. $box_conf="_".strtoupper($pi_name)."_CONF";
  1596. global $$box_conf;
  1597. $box_conf=$$box_conf;
  1598. $lang_box="LANG_".strtoupper($pi_name);
  1599. global $$lang_box;
  1600. $lang_box=$$lang_box;
  1601. $separater=$lang_box['field_separater'];
  1602. $noimage="lib/noimage.jpg";
  1603. $fieldsetfields=DATABOX_getfields($pi_name, $fieldset_id);
  1604. $retval = '';
  1605. if (is_array($fields)){
  1606. $S = $fields;
  1607. }else{
  1608. if( !empty( $selected )) {
  1609. $S = explode( ' ', $fields );
  1610. }else {
  1611. $S = array();
  1612. }
  1613. }
  1614. foreach( $S as $fid => $fvalue ){
  1615. $name=$addition_def[$fid]['name'];
  1616. $description=$addition_def[$fid]['description'];
  1617. $checkrequried=$addition_def[$fid]['checkrequried'];
  1618. $type=$addition_def[$fid]['type'];
  1619. $selectionary=$addition_def[$fid]['selectionary'];
  1620. $selectlist=$addition_def[$fid]['selectlist'];
  1621. $size=$addition_def[$fid]['size'];
  1622. $maxlength=$addition_def[$fid]['maxlength'];
  1623. $rows=$addition_def[$fid]['rows'];
  1624. $br=$addition_def[$fid]['br'];
  1625. $format=$addition_def[$fid]['format'];
  1626. $templatesetvar=$addition_def[$fid]['templatesetvar'];
  1627. $chk=false;
  1628. if (in_array($fid,$fieldsetfields )) {
  1629. //表示する
  1630. if ($addition_def[$fid]['allow_display']==='0') {
  1631. $chk=true;
  1632. //ログインユーザのみ
  1633. }else if ($addition_def[$fid]['allow_display']==='1'){
  1634. if ($chk_user>=1000) {
  1635. $chk=true;
  1636. }
  1637. //グループとadmin権のある人のみ表示
  1638. }else if ($addition_def[$fid]['allow_display']==='2'){
  1639. if ($chk_user>=1010) {
  1640. $chk=true;
  1641. }
  1642. //所有者とadmin権のある人のみ
  1643. }else if ($addition_def[$fid]['allow_display']==='3'){
  1644. if ($chk_user>=1011) {
  1645. $chk=true;
  1646. }
  1647. //admin権のある人のみ
  1648. }else if ($addition_def[$fid]['allow_display']==='4'){
  1649. if ($chk_user>=1100) {
  1650. $chk=true;
  1651. }
  1652. }
  1653. }
  1654. if ($chk) {
  1655. $fieldhtml="";//外画像の場合ファイル名
  1656. $fieldhtml_tn="";//サムネイルファイル名
  1657. $fieldhtmldisp="";//外画像 画像表示 (準備中)
  1658. $fieldhtmldisp_tn="";//外画像 画像表示 (準備中)
  1659. $fieldhtml_noimage="";
  1660. $fieldhtml_tn_noimage="";
  1661. $fieldhtml_tn_image="";//サムネイル
  1662. $fieldhtml_readfile="";//添付ファイルreadfile
  1663. $mstitems=array();
  1664. $fieldhtml_yes="";
  1665. switch ($type) {
  1666. case 12://画像(外記憶)(準備中)
  1667. $a=explode("|",$fvalue);
  1668. $fieldhtml=$a[0];//ファイル名
  1669. $fieldhtml_noimage=$a[0];
  1670. //
  1671. if ($fvalue===""){
  1672. $fieldhtml_noimage=$noimage;
  1673. $fieldhtml_tn_noimage=$noimage;
  1674. }else{
  1675. $fieldurl= $_CONF['site_url'] ."/".$box_conf['imgfile_frd'] ;
  1676. $fieldurl.= $a[0] ;
  1677. $fieldhtmldisp .="<img ";
  1678. $fieldhtmldisp .=" src=\"{$fieldurl}\"";
  1679. $fieldhtmldisp .=" border=\"0\"";
  1680. $fieldhtmldisp .=" alt=\"{$a[1]}\"";
  1681. $fieldhtmldisp .=" ".HTML.">";
  1682. //サムネイル
  1683. $filename = substr($fvalue, 0, strrpos($fvalue,"."));
  1684. $thum_filename = $filename . "-small.jpg";
  1685. $imgfld_thmb=$_CONF['path_html'].$box_conf['imgfile_thumb_frd'];
  1686. if(file_exists($imgfld_thmb.$thum_filename)) {
  1687. $fieldhtml_tn=$thum_filename;
  1688. $fieldhtml_tn_noimage=$thum_filename;
  1689. //
  1690. $fieldurl_tn= $_CONF['site_url'] ."/".$box_conf['imgfile_thumb_frd'] ;
  1691. $fieldurl_tn.= $thum_filename ;
  1692. //
  1693. $fieldhtml_tn_image .="<a href=\"{$fieldurl}\" target=\"_blank\">";
  1694. $fieldhtml_tn_image .="<img ";
  1695. $fieldhtml_tn_image .=" src=\"{$fieldurl_tn}\"";
  1696. $fieldhtml_tn_image .=" border=\"0\"";
  1697. $fieldhtml_tn_image .=" alt=\"{$a[1]}\"";
  1698. $fieldhtml_tn_image .=" ".XHTML.">";
  1699. $fieldhtml_tn_image .=" </a>";
  1700. }else{
  1701. $fieldhtml_tn_noimage=$noimage;
  1702. }
  1703. }
  1704. break;
  1705. case 13://添付ファイル
  1706. if ($fvalue==""){
  1707. }else{
  1708. $a=explode("|",$fvalue);
  1709. $fieldhtml .= $a[1];
  1710. $fieldhtml_readfile = $a[0];
  1711. }
  1712. break;
  1713. case 11://画像(DB記憶)
  1714. if ($fvalue==""){
  1715. }else{
  1716. $fieldhtml .="<img src=\"data:image/jpg;base64,";
  1717. $fieldhtml .="{$fvalue}\"".XHTML.">";
  1718. }
  1719. break;
  1720. case 2://いいえ/はい
  1721. $fieldhtml .= $lang_noyes[$fvalue];
  1722. break;
  1723. case 7://オプションリスト(選択肢)//@@@@@@
  1724. case 8://ラジオボタンリスト(選択肢)//@@@@@
  1725. $fieldhtml .= $selectionary[$fvalue];
  1726. break;
  1727. case 14://マルチセレクトリスト(選択肢)
  1728. case 24://チェックボックス(選択肢)
  1729. $wkary=explode(":",$fvalue);
  1730. $wk="";
  1731. for( $x = 0; $x < sizeof( $wkary ); $x++ ) {
  1732. $wk.=$selectionary[$wkary[$x]].$separater;
  1733. }
  1734. $fieldhtml .= rtrim($wk,$separater);
  1735. break;
  1736. case 10:// 複数行テキストフィールド(HTML NG)
  1737. $w=DATABOX_nl2br($fvalue);
  1738. $w=DATABOX_autolink($w);
  1739. $fieldhtml .= $w;
  1740. break;
  1741. case 9://オプションリスト(マスター)
  1742. case 16: //ラジオボタン(マスター)
  1743. $mstitems=DATABOX_getMstItems($selectlist,$fvalue,$pi_name);
  1744. $fieldhtml .= $mstitems['value'];
  1745. break;
  1746. case 18://マルチセレクトリスト(マスター)
  1747. case 25://チェックボックス(マスター)
  1748. $wkary=explode(":",$fvalue);
  1749. $wk="";
  1750. $wk_value2="";
  1751. $wk_disp="";
  1752. for( $x = 0; $x < sizeof( $wkary ); $x++ ) {
  1753. $mstitems=DATABOX_getMstItems($selectlist,$wkary[$x],$pi_name);
  1754. $wk.=$mstitems['value'].$separater;
  1755. $wk_value2.=$mstitems['value2'].$separater;
  1756. $wk_disp.=$mstitems['disp'].$separater;
  1757. }
  1758. $fieldhtml .= rtrim($wk,$separater);
  1759. $mstitems['value2'] = rtrim($wk_value2,$separater);
  1760. $mstitems['disp'] = rtrim($wk_disp,$separater);
  1761. $mstitems['no'] =$fvalue;
  1762. break;
  1763. case 4://日時
  1764. if ($fvalue<>""){
  1765. $w=DATABOX_getDateTimeFormat($fvalue,$format);
  1766. $fieldhtml .= $w[0];
  1767. }
  1768. break;
  1769. case 26://時刻
  1770. if ($fvalue<>""){
  1771. $fieldhtml .= DATABOX_getTimeformat($fvalue);
  1772. }
  1773. break;
  1774. case 22://日付
  1775. case 23://日付
  1776. case 3://日付
  1777. if ($fvalue<>""){
  1778. $fieldhtml .=strftime( $_CONF['shortdate'], $fvalue );
  1779. }
  1780. break;
  1781. case 21://money 通貨;
  1782. $dc = $_CONF['decimal_count'];
  1783. $ts = $_CONF['thousand_separator'];
  1784. $ds = $_CONF['decimal_separator'];
  1785. $fieldhtml .= number_format( (float)$fvalue, $dc, $ds, $ts );
  1786. break;
  1787. case 5://メールアドレス (準備中)';
  1788. case 6://url';
  1789. case 0:// 一行テキストフィールド
  1790. case 1:// 複数行テキストフィールド(HTML OK)
  1791. case 20:// 複数行テキストフィールド(HTML OK TinyMCE)
  1792. case 19:// 複数行テキストフィールド(HTML OK CKEditor)
  1793. default:
  1794. $fieldhtml .= $fvalue;
  1795. }
  1796. $templates->set_var('field_id', $fid);
  1797. $templates->set_var('field_type', $type);
  1798. //項目名
  1799. $templates->set_var('additionfield_name', $name);
  1800. $templates->set_var('additionfield'.$fid."_name", $name);
  1801. $templates->set_var($templatesetvar."_name", $name);
  1802. //説明
  1803. $templates->set_var('additionfield'.$fid."_description", $description);
  1804. $templates->set_var($templatesetvar."_description", $description);
  1805. //登録したテーマ変数名
  1806. $templates->set_var('additionfield_templatesetvar', $templatesetvar);
  1807. //
  1808. $templates->set_var('additionfield_value', $fieldhtml);
  1809. $templates->set_var('additionfield'.$fid, $fieldhtml);
  1810. $templates->set_var($templatesetvar, $fieldhtml);
  1811. $templates->set_var('additionfield_fvalue', $fvalue);
  1812. $templates->set_var('additionfield'.$fid."_value", $fvalue);
  1813. $templates->set_var($templatesetvar."_value", $fvalue);
  1814. if ($type==12){
  1815. $templates->set_var('display_a', 'display:');
  1816. }else{
  1817. $templates->set_var('display_a', 'display:none');
  1818. }
  1819. //(a_1)_tn サムネイルファイル名
  1820. $templates->set_var('additionfield_value_tn', $fieldhtml_tn);
  1821. $templates->set_var('additionfield'.$fid."_tn", $fieldhtml_tn);
  1822. $templates->set_var($templatesetvar."_tn", $fieldhtml_tn);
  1823. //(a_2)_noimage
  1824. $templates->set_var('additionfield_value_noimage', $fieldhtml_noimage);
  1825. $templates->set_var('additionfield'.$fid."_noimage", $fieldhtml_noimage);
  1826. $templates->set_var($templatesetvar."_noimage", $fieldhtml_noimage);
  1827. //(a_3)_tn_image サムネイルイメージ
  1828. $templates->set_var('additionfield_value_tn_image', $fieldhtml_tn_image);
  1829. $templates->set_var('additionfield'.$fid."_tn_image", $fieldhtml_tn_image);
  1830. $templates->set_var($templatesetvar."_tn_image", $fieldhtml_tn_image);
  1831. //(a_4)_tn_noimage サムネイルイメージ
  1832. $templates->set_var('additionfield_value_tn_noimage', $fieldhtml_tn_noimage);
  1833. $templates->set_var('additionfield'.$fid."_tn_noimage", $fieldhtml_tn_noimage);
  1834. $templates->set_var($templatesetvar."_tn_noimage", $fieldhtml_tn_noimage);
  1835. //(a_5)disp 画像(外記憶)表示
  1836. $templates->set_var('additionfield_value_disp', $fieldhtmldisp);
  1837. $templates->set_var('additionfield'.$fid."_disp", $fieldhtmldisp);
  1838. $templates->set_var($templatesetvar."_disp", $fieldhtmldisp);
  1839. if ( $type==9 OR $type==16 OR $type==18 ){
  1840. $templates->set_var('display_b', 'display:');
  1841. }else{
  1842. $templates->set_var('display_b', 'display:none');
  1843. }
  1844. //(b_1)マスターのvalue2
  1845. $templates->set_var('additionfield_value_mst_value2', $mstitems['value2']);
  1846. $templates->set_var('additionfield'.$fid."_mst_value2", $mstitems['value2']);
  1847. $templates->set_var($templatesetvar."_mst_value2", $mstitems['value2']);
  1848. //(b_2)マスターのdisp
  1849. $templates->set_var('additionfield_value_mst_disp', $mstitems['disp']);
  1850. $templates->set_var('additionfield'.$fid."_mst_disp", $mstitems['disp']);
  1851. $templates->set_var($templatesetvar."_mst_disp", $mstitems['disp']);
  1852. //(b_3)マスターのno
  1853. $templates->set_var('additionfield_value_mst_no', $mstitems['no']);
  1854. $templates->set_var('additionfield'.$fid."_mst_no", $mstitems['no']);
  1855. $templates->set_var($templatesetvar."_mst_no", $mstitems['no']);
  1856. //@@@@@ 準備中 $templates->set_var('additionfield'.$fid."_disptn", $fieldhtmldisp_tn);
  1857. //@@@@@ 準備中 $templates->set_var($templatesetvar."_disptn", $fieldhtmldisp_tn);
  1858. if ( $type==13 ){
  1859. $templates->set_var('display_c', 'display:');
  1860. }else{
  1861. $templates->set_var('display_c', 'display:none');
  1862. }
  1863. //(c)添付ファイルの記憶ファイル名(templatesetvar_(id)_(readfile))
  1864. $templates->set_var('additionfield_value_readfile', $fieldhtml_readfile);
  1865. $templates->set_var('additionfield'.$fid."_readfile", $fieldhtml_readfile);
  1866. $templates->set_var($templatesetvar."_readfile", $fieldhtml_readfile);
  1867. //必須チェック(templatesetvar_(id)_(requied))
  1868. $templates->set_var('additionfield'.$fid."_requried", $checkrequried);
  1869. $templates->set_var($templatesetvar."_requried", $checkrequried);
  1870. //文言
  1871. $templates->set_var('lang_download', $lang_box['download']);
  1872. $templates->set_var('lang_downloadrequired', $lang_box['downloadrequired']);
  1873. $templates->set_var('lang_display', $lang_box['display']);
  1874. $templates->set_var('lang_displayrequired', $lang_box['displayrequired']);
  1875. //=====
  1876. $templates->parse ('col_var', 'col', true);
  1877. $templates->parse ('additionfields', 'row', true);
  1878. $templates->set_var ('col_var', '');
  1879. }
  1880. }
  1881. return $retval;
  1882. }
  1883. //
  1884. function DATABOX_getMstItems(
  1885. $selectlist
  1886. ,$id
  1887. ,$pi_name
  1888. //DATABOX_getMstItems($id,$pi_name);
  1889. ){
  1890. if ($id==""){
  1891. return array();
  1892. }
  1893. global $_TABLES;
  1894. $table_mst=$_TABLES[strtoupper($pi_name).'_mst'];
  1895. $sql="SELECT * FROM {$table_mst} WHERE kind='{$selectlist}' AND no={$id}";
  1896. $result = DB_query($sql);
  1897. $numrows = DB_numRows ($result);
  1898. if ($numrows > 0) {
  1899. $A = DB_fetchArray($result, true);
  1900. $A = array_map('stripslashes', $A);
  1901. }else{
  1902. $A=array();
  1903. }
  1904. return $A;
  1905. }
  1906. function DATABOX_getcategoriesText(
  1907. $id
  1908. ,$group_id=0
  1909. ,$pi_name=""
  1910. )
  1911. // +---------------------------------------------------------------------------+
  1912. // | 機能 カテゴリメール送信用テキスト作成
  1913. // | 書式 DATABOX_getcategoriesText
  1914. // +---------------------------------------------------------------------------+
  1915. // | 引数 $id:
  1916. // | 引数 $group_id:
  1917. // | 引数 $pi_name: 'databox' 'userbox' 'formbox'
  1918. // +---------------------------------------------------------------------------+
  1919. // | 戻値 nomal:カテゴリテキスト
  1920. // +---------------------------------------------------------------------------+
  1921. //20101116
  1922. {
  1923. global $_TABLES;
  1924. global $_CONF;
  1925. if ($pi_name==""){
  1926. $lang_box="LANG_DATABOX";
  1927. $lang_box_admin="LANG_DATABOX_ADMIN";
  1928. $table_def_category=$_TABLES['DATABOX_def_category'];
  1929. $table_def_group=$_TABLES['DATABOX_def_group'];
  1930. $table_category=$_TABLES['DATABOX_category'];
  1931. }else{
  1932. $lang_box="LANG_".strtoupper($pi_name);
  1933. $lang_box_admin="LANG_".strtoupper($pi_name)."_ADMIN";
  1934. $table_def_category=$_TABLES[strtoupper($pi_name).'_def_category'];
  1935. $table_def_group=$_TABLES[strtoupper($pi_name).'_def_group'];
  1936. $table_category=$_TABLES[strtoupper($pi_name).'_category'];
  1937. }
  1938. global $$lang_box_admin;
  1939. $lang_box_admin=$$lang_box_admin;
  1940. global $$lang_box;
  1941. $lang_box=$$lang_box;
  1942. $retval = '';
  1943. $sql = "SELECT ".LB;
  1944. $sql .= " m1.category_id".LB;
  1945. $sql .= ",m1.name AS category_name".LB;
  1946. $sql .= ",m1.code AS category_code".LB;
  1947. //$sql .= ",m1.orderno";
  1948. $sql .= ",m1.categorygroup_id".LB;
  1949. //$sql .= ",m2.name AS group";
  1950. $sql .= ",m2.code AS group_code".LB;
  1951. $sql .= ",m2.group_id".LB;//@@@@@@
  1952. $sql .= " FROM ".LB;
  1953. $sql .= " {$table_category} AS t".LB;
  1954. $sql .= " , {$table_def_category} AS m1".LB;
  1955. $sql .= " , {$table_def_group} AS m2".LB;
  1956. $sql .= " WHERE ".LB;
  1957. $sql .= " t.id = ".$id.LB;
  1958. if ($group_id<>0){
  1959. $sql .= " AND m1.categorygroup_id=".$group_id.LB;
  1960. }
  1961. $sql .= " AND m1.category_id = t.category_id".LB;
  1962. $sql .= " AND m2.group_id = m1.categorygroup_id".LB;
  1963. $sql .= " ORDER by m1.categorygroup_id, m2.orderno, m1.orderno".LB;
  1964. $result = DB_query( $sql );
  1965. $nrows = DB_numRows( $result );
  1966. $separater=$lang_box['category_separater_text'];
  1967. $categpries="";
  1968. $old_group_id="";
  1969. $old_group_code="";
  1970. $categories_group ="";
  1971. $rt="";
  1972. for( $i = 0; $i < $nrows; $i++ ) {
  1973. $A = DB_fetchArray( $result, true );
  1974. if ($old_group_id<>$A['group_id']){
  1975. if ($categories_group<>""){
  1976. $categories_group=rtrim($categories_group,$separater);
  1977. $rt.=$categories_group.LB;
  1978. }
  1979. $categories_group ="";
  1980. $old_group_id=$A['group_id'];
  1981. }
  1982. $categories.=$A['category_name'].$separater;
  1983. $categories_group.=$A['category_name'].$separater;
  1984. }
  1985. $categories=rtrim($categories,$separater);
  1986. $categories_group=rtrim($categories_group,$separater);
  1987. $rt.=$categories_group.LB;
  1988. $retval.=$lang_box_admin['category'].": ".$categories.LB;
  1989. return $retval;
  1990. }
  1991. function DATABOX_getcategoriesDisp(
  1992. $id
  1993. ,$templates
  1994. ,$chk_user
  1995. ,$group_id=0
  1996. ,$pi_name=""
  1997. )
  1998. // +---------------------------------------------------------------------------+
  1999. // | 機能 カテゴリHRML作成
  2000. // | 書式 DATABOX_getcategoriesDisp
  2001. // +---------------------------------------------------------------------------+
  2002. // | 引数 $id:
  2003. // | 引数 $addition_def:
  2004. // | 引数 $templates:
  2005. // | 引数 $group_id:
  2006. // | 引数 $pi_name: 'databox' 'userbox' 'formbox'
  2007. // +---------------------------------------------------------------------------+
  2008. // | 戻値 nomal:カテゴリ表示用HTML
  2009. // +---------------------------------------------------------------------------+
  2010. //20101129
  2011. {
  2012. global $_TABLES;
  2013. global $_CONF;
  2014. if ($pi_name==""){
  2015. $lang_box="LANG_DATABOX";
  2016. $box_conf="_DATABOX_CONF";
  2017. $table_def_category=$_TABLES['DATABOX_def_category'];
  2018. $table_def_group=$_TABLES['DATABOX_def_group'];
  2019. $table_category=$_TABLES['DATABOX_category'];
  2020. }else{
  2021. $lang_box="LANG_".strtoupper($pi_name);
  2022. $box_conf="_".strtoupper($pi_name)."_CONF";
  2023. $table_def_category=$_TABLES[strtoupper($pi_name).'_def_category'];
  2024. $table_def_group=$_TABLES[strtoupper($pi_name).'_def_group'];
  2025. $table_category=$_TABLES[strtoupper($pi_name).'_category'];
  2026. }
  2027. global $$box_conf;
  2028. $box_conf=$$box_conf;
  2029. global $$lang_box;
  2030. $lang_box=$$lang_box;
  2031. $sql = "SELECT ";
  2032. $sql .= " group_id".LB;
  2033. $sql .= " ,code".LB;
  2034. $sql .= " FROM ";
  2035. $sql .= " {$table_def_group} ".LB;
  2036. $result = DB_query( $sql );
  2037. $nrows = DB_numRows( $result );
  2038. for( $i = 0; $i < $nrows; $i++ ) {
  2039. $A = DB_fetchArray( $result, true );
  2040. $A = array_map('stripslashes', $A);
  2041. $gid=$A['group_id'];
  2042. $gcode=$A['code'];
  2043. $templates->set_var('group_'.$gid, "");
  2044. $templates->set_var('group_'.$gcode, "");
  2045. $templates->set_var('group_'.$gid."_code", "");
  2046. $templates->set_var('group_'.$gcode."_code", "");
  2047. $templates->set_var('grouplink_'.$gid, "");
  2048. $templates->set_var('grouplink_'.$gid."_code", "");
  2049. $templates->set_var('grouplink_'.$gcode, "");
  2050. $templates->set_var('grouplink_'.$gcode."_code", "");
  2051. }
  2052. $retval = '';
  2053. $sql = "SELECT ".LB;
  2054. $sql .= " m1.category_id".LB;
  2055. $sql .= ",m1.name AS category_name".LB;
  2056. $sql .= ",m1.code AS category_code".LB;
  2057. //$sql .= ",m1.orderno";
  2058. $sql .= ",m1.categorygroup_id".LB;
  2059. $sql .= ",m1.allow_display".LB;
  2060. //$sql .= ",m2.name AS group";
  2061. $sql .= ",m2.code AS group_code".LB;
  2062. $sql .= ",m2.group_id".LB;//@@@@@@
  2063. $sql .= " FROM ".LB;
  2064. $sql .= " {$table_category} AS t".LB;
  2065. $sql .= " , {$table_def_category} AS m1".LB;
  2066. $sql .= " , {$table_def_group} AS m2".LB;
  2067. $sql .= " WHERE ".LB;
  2068. $sql .= " t.id = ".$id.LB;
  2069. if ($group_id<>0){
  2070. $sql .= " AND m1.categorygroup_id=".$group_id.LB;
  2071. }
  2072. $sql .= " AND m1.category_id = t.category_id".LB;
  2073. $sql .= " AND m2.group_id = m1.categorygroup_id".LB;
  2074. $sql .= " ORDER by m1.categorygroup_id, m2.orderno, m1.orderno,m1.category_id".LB;
  2075. $result = DB_query( $sql );
  2076. $nrows = DB_numRows( $result );
  2077. $separater=$lang_box['category_separater'];
  2078. $separater_code=$lang_box['category_separater_code'];
  2079. $separater_pipeline="|";
  2080. $categpries="";
  2081. $old_group_id="";
  2082. $old_group_code="";
  2083. $categories_group ="";
  2084. $categories_link_id_group ="";
  2085. $categories_link_code_group ="";
  2086. $categories_group2 ="";
  2087. $categories_link_id_group2 ="";
  2088. $categories_link_code_group2 ="";
  2089. $categories_group_pipeline ="";
  2090. //group_id2, group_code2, grouplinkid2, grouplinkcode2,
  2091. //group_id がカテゴリの名称を表示するのに対し、
  2092. //group_id2はカテゴリのコードを表示する。
  2093. //$categories_group $categories_link_id_group $categories_link_code_group
  2094. //group_pipelineはカテゴリのコードパイプライン区切を表示する。
  2095. //$categories_group_pipeline
  2096. for( $i = 0; $i < $nrows; $i++ ) {
  2097. $A = DB_fetchArray( $result, true );
  2098. $A = array_map('stripslashes', $A);
  2099. $chk=false;
  2100. //表示する
  2101. if ($A['allow_display']==='0') {
  2102. $chk=true;
  2103. //ログインユーザのみ
  2104. }else if ($A['allow_display']==='1'){
  2105. if ($chk_user>=1000) {
  2106. $chk=true;
  2107. }
  2108. //グループとadmin権のある人のみ表示
  2109. }else if ($A['allow_display']==='2'){
  2110. if ($chk_user>=1010) {
  2111. $chk=true;
  2112. }
  2113. //所有者とadmin権のある人のみ
  2114. }else if ($A['allow_display']==='3'){
  2115. if ($chk_user>=1011) {
  2116. $chk=true;
  2117. }
  2118. //admin権のある人のみ
  2119. }else if ($A['allow_display']==='4'){
  2120. if ($chk_user>=1100) {
  2121. $chk=true;
  2122. }
  2123. }
  2124. if ($chk==false){
  2125. continue;
  2126. }
  2127. if ($old_group_id<>$A['group_id']){
  2128. if ($categories_group<>""){
  2129. $categories_group=rtrim($categories_group,$separater);
  2130. $templates->set_var('group_'.$old_group_id, $categories_group);
  2131. $templates->set_var('group_'.$old_group_code, $categories_group);
  2132. $categories_group2=rtrim($categories_group2,$separater_code);
  2133. $templates->set_var('group_'.$old_group_id."_code", $categories_group2);
  2134. $templates->set_var('group_'.$old_group_code."_code", $categories_group2);
  2135. $categories_group_pipeline=rtrim($categories_group_pipeline,$separater_pipeline);//@@
  2136. $templates->set_var('group_'.$old_group_id."_pipeline", $categories_group_pipeline);//@@
  2137. $templates->set_var('group_'.$old_group_code."_pipeline", $categories_group_pipeline);//@@
  2138. $categories_link_id_group=rtrim($categories_link_id_group,$separater);
  2139. $templates->set_var('grouplink_'.$old_group_id, $categories_link_id_group);
  2140. $categories_link_id_group2=rtrim($categories_link_id_group2,$separater_code);
  2141. $templates->set_var('grouplink_'.$old_group_id."_code", $categories_link_id_group2);
  2142. $categories_link_code_group=rtrim($categories_link_code_group,$separater);
  2143. $templates->set_var('grouplink_'.$old_group_code, $categories_link_code_group);
  2144. $categories_link_code_group2=rtrim($categories_link_code_group2,$separater_code);
  2145. $templates->set_var('grouplink_'.$old_group_code."_code", $categories_link_code_group2);
  2146. }
  2147. $categories_group ="";
  2148. $categories_link_id_group ="";
  2149. $categories_link_code_group ="";
  2150. $categories_group2 ="";
  2151. $categories_link_id_group2 ="";
  2152. $categories_link_code_group2 ="";
  2153. $categories_group_pipeline="";//@@
  2154. $old_group_id=$A['group_id'];
  2155. $old_group_code=$A['group_code'];
  2156. }
  2157. $categories.=$A['category_name'].$separater;
  2158. $categories_group.=$A['category_name'].$separater;
  2159. $categories_group2.=$A['category_code'].$separater_code;
  2160. $categories_group_pipeline.=$A['category_code'].$separater_pipeline;
  2161. $name=$A['category_name'];
  2162. $code=COM_applyFilter($A['category_code']);
  2163. $url=$_CONF['site_url'] ."/".$pi_name."/category.php";
  2164. $url_code=$url;
  2165. $url_code.="?code=".$A['category_code'];
  2166. $url_code.="&m=code";
  2167. $url_code = COM_buildUrl( $url_code );
  2168. $url_id=$url;
  2169. $url_id.="?id=".$A['category_id'];
  2170. $url_id.="&m=id";
  2171. $url_id= COM_buildUrl( $url_id );
  2172. $category_link_id= COM_createLink($name, $url_id);
  2173. $category_link_code= COM_createLink($name, $url_code);
  2174. $category_link_id2= COM_createLink($code, $url_id);
  2175. $category_link_code2= COM_createLink($code, $url_code);
  2176. $categories_link_id.=$category_link_id.$separater;
  2177. $categories_link_id_group.=$category_link_id.$separater;
  2178. $categories_link_id_group2.=$category_link_id2.$separater_code;//@@
  2179. $categories_link_code.=$category_link_code.$separater;
  2180. $categories_link_code_group.=$category_link_code.$separater;
  2181. $categories_link_code_group2.=$category_link_code2.$separater_code;//@@
  2182. }
  2183. $categories=rtrim($categories,$separater);
  2184. $templates->set_var('categories', $categories);
  2185. $categories_link_code=rtrim($categories_link_code,$separater);
  2186. $categories_link_id=rtrim($categories_link_id,$separater);
  2187. if ($box_conf['categoriescode']){
  2188. $categorieslink=$categories_link_code;
  2189. }else{
  2190. $categorieslink=$categories_link_id;
  2191. }
  2192. $templates->set_var('categorieslink', $categorieslink);
  2193. $templates->set_var('categorieslinkcode', $categories_link_code);
  2194. $templates->set_var('categorieslinkid', $categories_link_id);
  2195. $categories_group=rtrim($categories_group,$separater);
  2196. $categories_group2=rtrim($categories_group2,$separater_code);
  2197. $categories_group_pipeline=rtrim($categories_group_pipeline,$separater_pipeline);//@@
  2198. $templates->set_var('group_'.$old_group_id, $categories_group);
  2199. $templates->set_var('group_'.$old_group_code, $categories_group);
  2200. $templates->set_var('group_'.$old_group_id."_code", $categories_group2);
  2201. $templates->set_var('group_'.$old_group_code."_code", $categories_group2);
  2202. $templates->set_var('group_'.$old_group_id."_pipeline", $categories_group_pipeline);//@@
  2203. $templates->set_var('group_'.$old_group_code."_pipeline", $categories_group_pipeline);//@@
  2204. $categories_link_id_group=rtrim($categories_link_id_group,$separater);
  2205. $templates->set_var('grouplink_'.$old_group_id, $categories_link_id_group);
  2206. $categories_link_id_group2=rtrim($categories_link_id_group2,$separater_code);//@@
  2207. $templates->set_var('grouplink_'.$old_group_id."_code", $categories_link_id_group2);//@@
  2208. $categories_link_code_group=rtrim($categories_link_code_group,$separater);
  2209. $templates->set_var('grouplink_'.$old_group_code, $categories_link_code_group);
  2210. $categories_link_code_group2=rtrim($categories_link_code_group2,$separater_code);//@@
  2211. $templates->set_var('grouplink_'.$old_group_code."_code", $categories_link_code_group2);//@@
  2212. return $retval;
  2213. }
  2214. function DATABOX_getcategoriesinp(
  2215. $selected = ""
  2216. ,$fieldset_id=""
  2217. ,$pi_name=""
  2218. ,$chk_user=9999
  2219. )
  2220. {
  2221. global $_TABLES;
  2222. if ($pi_name==""){
  2223. $table_def_category=$_TABLES['DATABOX_def_category'];
  2224. $table_def_group=$_TABLES['DATABOX_def_group'];
  2225. $table_def_fieldset_group=$_TABLES['DATABOX_def_fieldset_group'];
  2226. $table_mst=$_TABLES['DATABOX_mst'];
  2227. }else{
  2228. $table_def_category=$_TABLES[strtoupper($pi_name).'_def_category'];
  2229. $table_def_group=$_TABLES[strtoupper($pi_name).'_def_group'];
  2230. $table_def_fieldset_group=$_TABLES[strtoupper($pi_name).'_def_fieldset_group'];
  2231. $table_mst=$_TABLES[strtoupper($pi_name).'_mst'];
  2232. }
  2233. //
  2234. if (is_array($selected)){
  2235. $S = $selected;
  2236. }else{
  2237. if( !empty( $selected )) {
  2238. $S = explode( ' ', $selected );
  2239. }else {
  2240. $S = array();
  2241. }
  2242. }
  2243. //
  2244. $retval = '';
  2245. $sql = "SELECT ";
  2246. $sql .= "m2.group_id".LB;
  2247. $sql .= ",m2.name AS group_name".LB;
  2248. $sql .= ",m2.input_type".LB;
  2249. $sql .= ",m2.allow_edit".LB;
  2250. $sql .= " FROM ".LB;
  2251. $sql .= " {$table_def_group} AS m2".LB;
  2252. if ($fieldset_id<>0){
  2253. $sql .= " ,{$table_def_fieldset_group} AS m3".LB;
  2254. $sql .= " WHERE ".LB;
  2255. $sql .= " m2.group_id = m3.group_id".LB;
  2256. $sql .= " AND m3.fieldset_id = ".$fieldset_id .LB;
  2257. }
  2258. $sql .= " ORDER BY m2.orderno".LB;
  2259. $result = DB_query( $sql );
  2260. $nrows = DB_numRows( $result );
  2261. $categoryids="";
  2262. for( $i = 0; $i < $nrows; $i++ ) {
  2263. $A = DB_fetchArray( $result, true );
  2264. $chk=false;
  2265. $disabled="disabled";
  2266. if ($chk_user===9999){
  2267. $chk=true;
  2268. $disabled="";
  2269. }else{
  2270. //編集可能
  2271. if ($A['allow_edit']==='0') {
  2272. $chk=true;
  2273. $disabled="";
  2274. //グループとadmin権のある人のみ表示
  2275. }else if ($A['allow_edit']==='2'){
  2276. if ($chk_user>=1010) {
  2277. $chk=true;
  2278. $disabled="";
  2279. }
  2280. //所有者とadmin権のある人のみ
  2281. }else if ($A['allow_edit']==='3'){
  2282. if ($chk_user>=1011) {
  2283. $chk=true;
  2284. $disabled="";
  2285. }
  2286. //編集不可表示のみ
  2287. }else if ($A['allow_edit']==='4'){
  2288. $chk=true;
  2289. }
  2290. }
  2291. if ($chk==false) {
  2292. continue;
  2293. }
  2294. $sql2 = "SELECT ";
  2295. $sql2 .= " m1.category_id".LB;
  2296. $sql2 .= ",m1.name".LB;
  2297. $sql2 .= ",m1.orderno".LB;
  2298. $sql2 .= " FROM {$table_def_category} AS m1".LB;
  2299. $sql2 .= " WHERE ".LB;
  2300. $sql2 .= " m1.categorygroup_id=".$A['group_id'].LB;
  2301. $sql2 .= " ORDER BY m1.orderno".LB;
  2302. $result2 = DB_query( $sql2 );
  2303. $nrows2 = DB_numRows( $result2 );
  2304. if ($nrows2>0){
  2305. $retval .="<div class=\"databox_admin_data_title\">";
  2306. $retval .=$A['group_name'];
  2307. $retval .="</div>".LB;
  2308. if ($A['input_type']==1){
  2309. $retval .='<select name="category[]" multiple style="height:10em" '.$disabled.' >'.LB;
  2310. }else if ($A['input_type']==3){
  2311. $retval .='<select name="category[]" '. $disabled .' >'.LB;
  2312. }
  2313. for( $i2 = 0; $i2 < $nrows2; $i2++ ) {
  2314. $A2 = DB_fetchArray( $result2, true );
  2315. if ($disabled==""){
  2316. $categoryids.=$A2['category_id']."|";
  2317. }
  2318. $checked=" ";
  2319. for( $x = 0; $x < sizeof( $S ); $x++ ) {
  2320. if( $A2['category_id'] == $S[$x] ) {
  2321. if ($A['input_type']==0 OR $A['input_type']==2){
  2322. $checked= ' checked="checked" ';
  2323. }else{
  2324. $checked= ' selected ';
  2325. }
  2326. }
  2327. }
  2328. if ($A['input_type']==0){
  2329. $retval .= '<span style="white-space:nowrap">';
  2330. $retval .= '<input type="checkbox" name="category[]" value="' . $A2['category_id'] ;
  2331. $retval .= '"';
  2332. $retval .= $checked;
  2333. $retval .= $disabled.' >' . stripslashes( $A2['name'] ) . '</span>' . LB;
  2334. }else if ($A['input_type']==1){
  2335. $retval .= '<option value="' . $A2['category_id'] . '"';
  2336. $retval .= $checked;
  2337. $retval .= ' >' . stripslashes( $A2['name'] ) ;
  2338. $retval .= '</option>' . LB;
  2339. }else if ($A['input_type']==2){
  2340. $retval .= '<input type="radio" name="category[]" value="' . $A2['category_id'];
  2341. $retval .= '"';
  2342. $retval .= $checked;
  2343. $retval .= ' '.$disabled.' >' . stripslashes( $A2['name'] ) . '</span>' . LB;
  2344. }else if ($A['input_type']==3){
  2345. $retval .= '<option value="' . $A2['category_id'] . '"';
  2346. $retval .= $checked;
  2347. $retval .= ' >' . stripslashes( $A2['name'] ) ;
  2348. $retval .= '</option>' . LB;
  2349. }
  2350. }
  2351. if ($A['input_type']==1 OR $A['input_type']==3 ){
  2352. $retval .='</select>';
  2353. }
  2354. }
  2355. }
  2356. if ($categoryids==""){
  2357. }else{
  2358. $categoryids=substr($categoryids,0,strlen($categoryids)-1);
  2359. $retval .= " <input type='hidden' name='categories' value='{$categoryids}'>";
  2360. }
  2361. return $retval;
  2362. }
  2363. function DATABOX_getaddtionfields(
  2364. $id
  2365. ,$addition_def
  2366. ,$pi_name
  2367. ,$field_id=0
  2368. )
  2369. // +---------------------------------------------------------------------------+
  2370. // | 機能 追加項目値を返す     |
  2371. // | 書式 DATABOX_getadditionfields($id,$addition_def,$tbl_prefix,$field_id)
  2372. // +---------------------------------------------------------------------------+
  2373. // | 引数 $pi_name: 'databox' 'userbox' 'formbox'
  2374. // +---------------------------------------------------------------------------+
  2375. // | 戻値 nomal:追加項目値の配列
  2376. // +---------------------------------------------------------------------------+
  2377. //update 20110204
  2378. {
  2379. global $_TABLES;
  2380. $table_def_field=$_TABLES[strtoupper($pi_name).'_def_field'];
  2381. $table_addition=$_TABLES[strtoupper($pi_name).'_addition'];
  2382. $lang_noyes="LANG_".strtoupper($pi_name)."_NOYES";
  2383. global $$lang_noyes;
  2384. $lang_noyes=$$lang_noyes;
  2385. $retval=array();
  2386. $sql = "SELECT ";
  2387. $sql .= " value";
  2388. $sql .= ",t.field_id";
  2389. $sql .= " FROM {$table_addition} AS t";
  2390. $sql .= " , {$table_def_field} AS m";
  2391. $sql .= " WHERE ";
  2392. $sql .= " t.id={$id}";
  2393. $sql .= " AND t.field_id=m.field_id";
  2394. if ($field_id<>0){
  2395. $sql .= " AND t.field_id=".$field_id;
  2396. }
  2397. $sql .= " ORDER BY m.orderno";
  2398. $result = DB_query( $sql );
  2399. $nrows = DB_numRows( $result );
  2400. for( $i = 0; $i < $nrows; $i++ ) {
  2401. $A = DB_fetchArray( $result, true );
  2402. $fid=$A["field_id"];
  2403. $value=$A["value"];
  2404. $fieldvalue=DATABOX_getfieldvalue(
  2405. $value
  2406. ,$addition_def[$fid]['type']
  2407. ,$addition_def[$fid]['selectionary']
  2408. ,$lang_noyes
  2409. ,$addition_def[$fid]['selectlist']
  2410. ,$pi_name
  2411. );
  2412. $retval[$fid]=$fieldvalue;
  2413. }
  2414. return $retval;
  2415. }
  2416. function DATABOX_getfieldvalue(
  2417. $value
  2418. ,$type
  2419. ,$selectionary
  2420. ,$lang_noyes
  2421. ,$selectlist
  2422. ,$pi_name
  2423. )
  2424. // +---------------------------------------------------------------------------+
  2425. // | 機能 追加項目値を返す     |
  2426. // | 書式 DATABOX_getfieldvalue($value,$type,$selectionary,$lang_noyes)
  2427. // +---------------------------------------------------------------------------+
  2428. // | 引数 $value:
  2429. // | 引数 $type:
  2430. // | 引数 $selectionary:
  2431. // | 引数 $lang_noyes:
  2432. // +---------------------------------------------------------------------------+
  2433. // | 戻値 nomal:追加項目値
  2434. // +---------------------------------------------------------------------------+
  2435. //update 20110204
  2436. {
  2437. global $_TABLES;
  2438. global $_CONF;
  2439. switch ($type) {
  2440. case 2://いいえ/はい
  2441. $fieldvalue = $lang_noyes[$value];
  2442. break;
  2443. case 7://オプションリスト(選択肢)
  2444. case 8://ラジオボタンリスト(選択肢)
  2445. $fieldvalue= $selectionary[$value];
  2446. break;
  2447. case 9://オプションリスト(マスター)';
  2448. case 16://ラジオボタンリスト(マスター)';
  2449. if ($value==""){
  2450. $fieldvalue="";
  2451. }else{
  2452. $fieldvalue=DB_getItem($_TABLES[strtoupper($pi_name).'_mst']
  2453. ,"value"
  2454. ,"kind='{$selectlist}' AND no={$value}");
  2455. }
  2456. break;
  2457. case 4://日時
  2458. $w=COM_getUserDateTimeFormat($value);
  2459. $fieldvalue= $w[0];
  2460. break;
  2461. case 3://日付
  2462. $fieldvalue=strftime( $_CONF['shortdate'], $value );
  2463. break;
  2464. case 5://メールアドレス (準備中)';
  2465. case 6://url (準備中)';
  2466. case 0:// 一行テキストフィールド
  2467. case 1:// 複数行テキストフィールド(HTML OK)
  2468. case 10:// 複数行テキストフィールド(HTML NG)
  2469. case 20:// 複数行テキストフィールド(HTML OK TinyMCE)
  2470. default:
  2471. $fieldvalue = $value;
  2472. }
  2473. return $fieldvalue;
  2474. }
  2475. function DATABOX_saveaddtiondatas(
  2476. $id
  2477. ,$fldary = ""
  2478. ,$addition_def=""
  2479. ,$pi_name=""
  2480. )
  2481. // +---------------------------------------------------------------------------+
  2482. // | 機能 追加項目書込 |
  2483. // | 書式
  2484. // +---------------------------------------------------------------------------+
  2485. // | 引数 $ide:
  2486. // | 引数 $fldary:
  2487. // | 引数 $addition_def:
  2488. // | 引数 $pi_name: 'databox' 'userbox' 'formbox'
  2489. // +---------------------------------------------------------------------------+
  2490. // | 戻値 nomal:
  2491. // +---------------------------------------------------------------------------+
  2492. //
  2493. {
  2494. global $_TABLES;
  2495. if ($pi_name==""){
  2496. $table=$_TABLES['DATABOX_addition'];
  2497. }else{
  2498. $table=$_TABLES[strtoupper($pi_name).'_addition'];
  2499. }
  2500. $rt=DB_delete($table,"id",$id);
  2501. if (is_array($fldary)){
  2502. foreach( $fldary as $field_id => $value ){
  2503. $sql="INSERT INTO {$table} (";
  2504. $sql.="id, field_id,value ";
  2505. $sql.=") VALUES (";
  2506. $sql.="{$id},{$field_id}";
  2507. if ($value<>"") {
  2508. $sql.=", '{$value}'";
  2509. }else{
  2510. $sql.=", NULL";
  2511. }
  2512. $sql.=")";
  2513. DB_query($sql);
  2514. }
  2515. }
  2516. return ;
  2517. }
  2518. function DATABOX_saveaddtiondatas_update(
  2519. $id
  2520. ,$fldary = ""
  2521. ,$addition_def=""
  2522. ,$pi_name=""
  2523. )
  2524. // +---------------------------------------------------------------------------+
  2525. // | 機能 追加項目書込 user用
  2526. // | 書式 $rt=DATABOX_saveaddtiondatas_update
  2527. // | ($id,$additionfields,$addition_def,$pi_name);
  2528. // +---------------------------------------------------------------------------+
  2529. // | 引数 $ide:
  2530. // | 引数 $fldary:
  2531. // | 引数 $addition_def:
  2532. // | 引数 $pi_name: 'databox' 'userbox' 'formbox'
  2533. // +---------------------------------------------------------------------------+
  2534. // | 戻値 nomal: |
  2535. // +---------------------------------------------------------------------------+
  2536. //
  2537. {
  2538. global $_TABLES;
  2539. if ($pi_name==""){
  2540. $table=$_TABLES['DATABOX_addition'];
  2541. }else{
  2542. $table=$_TABLES[strtoupper($pi_name).'_addition'];
  2543. }
  2544. if (is_array($fldary)){
  2545. foreach( $fldary as $field_id => $value ){
  2546. //if ($addition_def[$field_id]['type']=11){
  2547. $sql="UPDATE ".$table ." SET ";
  2548. if ($value<>"") {
  2549. $sql.=" value ='".$value."'";
  2550. }else{
  2551. $sql.=" value =NULL";
  2552. }
  2553. $sql.=" WHERE id=".$id." AND field_id=".$field_id;
  2554. DB_query($sql);
  2555. }
  2556. }
  2557. return ;
  2558. }
  2559. function DATABOX_cleanaddtiondatas(
  2560. &$fldary
  2561. ,$addition_def
  2562. ,&$fnmary
  2563. ,&$delary
  2564. ,&$dateary
  2565. ,&$altary
  2566. ,$addslash = true
  2567. )
  2568. // +---------------------------------------------------------------------------+
  2569. // | 機能 追加項目clean
  2570. // | 書式 DATABOX_cleanadditiondatas($fldary,$typeary)
  2571. // +---------------------------------------------------------------------------+
  2572. // | 引数 $fldary:
  2573. // | 引数 $addition_def
  2574. // | 引数 $fnmary
  2575. // | 引数 $delary
  2576. // | 引数 $addslash
  2577. // +---------------------------------------------------------------------------+
  2578. // | 戻値 nomal: |
  2579. // +---------------------------------------------------------------------------+
  2580. //update 20131022 12
  2581. {
  2582. if (is_array($fldary)){
  2583. foreach( $fldary as $field_id => $value ){
  2584. $type=$addition_def[$field_id]['type'];
  2585. $textconv=$addition_def[$field_id]['textconv'];
  2586. $textcheck=$addition_def[$field_id]['textcheck'];
  2587. $wk=$value;
  2588. //入力値変換
  2589. switch ($type) {
  2590. case 0:// 一行テキストフィールド
  2591. case 1:// 複数行テキストフィールド(HTML OK)
  2592. case 10:// 複数行テキストフィールド(HTML NG)
  2593. case 20:// 複数行テキストフィールド(HTML OK TinyMCE)
  2594. if (($textconv==10)
  2595. OR ($textcheck>=11 AND $textcheck<=14)){ //半角チェック;
  2596. $wk = mb_convert_kana($wk,"ak");
  2597. }else if ($textconv==20){ //全角に変換する';
  2598. $wk = mb_convert_kana($wk,"AKV");
  2599. }
  2600. break;
  2601. }
  2602. //
  2603. switch ($type) {
  2604. case 11:// 図
  2605. break;
  2606. case 0:// 一行テキスト
  2607. case 10://複数行テキスト
  2608. $wk=COM_stripslashes($wk);
  2609. $wk=COM_checkHTML (COM_checkWords ($wk));
  2610. break;
  2611. case 1://HTML
  2612. case 20://TinyMCE
  2613. case 19://CKEditor
  2614. $wk=COM_stripslashes($wk);
  2615. break;
  2616. case 2://いいえ/はい
  2617. $wk=COM_applyFilter($wk,true);
  2618. break;
  2619. case 3://日付
  2620. $wk_year=$_POST['afield'.$field_id.'_year'];
  2621. $wk_month=$_POST['afield'.$field_id.'_month'];
  2622. $wk_day=$_POST['afield'.$field_id.'_day'];
  2623. $wk=$wk_year."-".$wk_month."-".$wk_day;
  2624. $dateary[$field_id]['year']=$wk_year;//@@@@@
  2625. $dateary[$field_id]['month']=$wk_month;//@@@@@
  2626. $dateary[$field_id]['day']=$wk_day;//@@@@@
  2627. break;
  2628. case 22://日付
  2629. case 23://日付
  2630. $ary_wk=date_parse( $wk);
  2631. if ($ary_wk[error_count]==0){
  2632. $dateary[$field_id]['month']= $ary_wk[month];
  2633. $dateary[$field_id]['day']= $ary_wk[day];
  2634. $dateary[$field_id]['year']= $ary_wk[year];
  2635. }else{
  2636. $wk="";
  2637. $dateary[$field_id]['month']= "";
  2638. $dateary[$field_id]['day']= "";
  2639. $dateary[$field_id]['year']= "";
  2640. }
  2641. break;
  2642. case 4://日時
  2643. $wk_year=$_POST['afield'.$field_id.'_year'];
  2644. $wk_month=$_POST['afield'.$field_id.'_month'];
  2645. $wk_day=$_POST['afield'.$field_id.'_day'];
  2646. $wk_hour=$_POST['afield'.$field_id.'_hour'];
  2647. $wk_minute=$_POST['afield'.$field_id.'_minute'];
  2648. $wk_ampm=$_POST['afield'.$field_id.'_ampm'];
  2649. $dateary[$field_id]['year']=$wk_year;//@@@@@
  2650. $dateary[$field_id]['month']=$wk_month;//@@@@@
  2651. $dateary[$field_id]['day']=$wk_day;//@@@@@
  2652. $dateary[$field_id]['hour']=$wk_hour;//@@@@@
  2653. $dateary[$field_id]['minute']=$wk_minute;//@@@@@
  2654. $dateary[$field_id]['ampm']=$wk_ampm;//@@@@@
  2655. if ($wk_ampm == 'pm') {
  2656. if ($wk_hour < 12) {
  2657. $wk_hour = $wk_hour + 12;
  2658. }
  2659. }
  2660. if ($wk_ampm == 'am' AND $wk_hour == 12) {
  2661. $wk_hour = '00';
  2662. }
  2663. $wk=$wk_year."-".$wk_month."-".$wk_day ." ".$wk_hour.":".$wk_minute;
  2664. break;
  2665. case 26://時刻
  2666. $wk=COM_applyFilter($wk);
  2667. $wk=COM_checkHTML (COM_checkWords ($wk));
  2668. break;
  2669. case 24://チェックボックス(選択肢)
  2670. case 25://チェックボックス(マスター)
  2671. case 14://マルチセレクトリスト(選択肢)
  2672. case 18://マルチセレクトリスト(マスター)
  2673. $wk=implode ($wk,":");
  2674. break;
  2675. case 12:// 画像(ファイル保存)
  2676. $fnmary[$field_id]=COM_applyFilter($fnmary[$field_id]);
  2677. $delary[$field_id]=COM_applyFilter($delary[$field_id]);
  2678. $wk=COM_applyFilter($wk);
  2679. $wk=COM_checkHTML (COM_checkWords ($wk));
  2680. $wk2=COM_applyFilter($altary[$field_id]);
  2681. $wk2=COM_checkHTML (COM_checkWords ($wk2));
  2682. $altary[$field_id]=$wk2;
  2683. $a=explode("|",$wk);
  2684. $wk=$a[0]."|".$wk2;
  2685. break;
  2686. case 13:// 添付ファイル
  2687. $fnmary[$field_id]=COM_applyFilter($fnmary[$field_id]);
  2688. $delary[$field_id]=COM_applyFilter($delary[$field_id]);
  2689. $wk=COM_applyFilter($wk);
  2690. $wk=COM_checkHTML (COM_checkWords ($wk));
  2691. $wk2=COM_applyFilter($delary[$field_id]);
  2692. $delary[$field_id]=COM_checkHTML (COM_checkWords ($wk2));
  2693. break;
  2694. case 7://オプションリスト(選択肢)
  2695. case 8://ラジオボタンリスト(選択肢)
  2696. case 9://オプションリスト(マスター)';
  2697. case 5://メールアドレス';
  2698. case 6://url';
  2699. default:
  2700. $wk=COM_applyFilter($wk);
  2701. $wk=COM_checkHTML (COM_checkWords ($wk));
  2702. }
  2703. if ($addslash){
  2704. $wk=addslashes ($wk);
  2705. }
  2706. $fldary[$field_id] =$wk;
  2707. }
  2708. }
  2709. return $fldary;
  2710. }
  2711. function DATABOX_checkaddtiondatas(
  2712. &$fldary
  2713. ,$addition_def
  2714. ,$pi_name
  2715. ,$fldary_fnm=""
  2716. ,$fldary_del=""
  2717. ,$fldary_alt=""
  2718. )
  2719. // +---------------------------------------------------------------------------+
  2720. // | 機能 追加項目check
  2721. // | 書式 DATABOX_checkdditiondatas($fldary,$typeary,$pi_data)
  2722. // | 書式 DATABOX_checkdditiondatas($additionfields,$addition_def,$pi_name
  2723. // | ,$additionfields_fnm,$additionfields_del)
  2724. // +---------------------------------------------------------------------------+
  2725. // | 引数 $fldary:追加項目データ配列
  2726. // | 引数 $addition_def:追加項目定義
  2727. // | 引数 $pi_name: 'databox' 'userbox' 'formbox'
  2728. // +-----
  2729. // | 引数 $fldary_fnm:追加項目データ配列 アップロードファイル名
  2730. // | 引数 $fldary_del:追加項目データ配列 アップロードファイル削除
  2731. // +---------------------------------------------------------------------------+
  2732. // | 戻値 nomal:
  2733. // +---------------------------------------------------------------------------+
  2734. //update
  2735. {
  2736. global $_CONF;
  2737. global $LANG04;
  2738. global $_FILES;
  2739. $lang_box_admin="LANG_".strtoupper($pi_name)."_ADMIN";
  2740. global $$lang_box_admin;
  2741. $lang_box_admin=$$lang_box_admin;
  2742. $box_conf="_".strtoupper($pi_name)."_CONF";
  2743. global $$box_conf;
  2744. $box_conf=$$box_conf;
  2745. $rt="";
  2746. if (is_array($fldary)){
  2747. foreach( $fldary as $field_id => $value ){
  2748. //必須
  2749. if ($addition_def[$field_id]['checkrequried']==1){
  2750. if ($value ===""){
  2751. $rt.=$addition_def[$field_id]['name'].": ".$lang_box_admin['err_checkrequried'] ;
  2752. $rt.="<br ".XHTML.">".LB;
  2753. }
  2754. //url email date
  2755. }
  2756. //図 外記憶
  2757. if ($addition_def[$field_id]['type']==12){//図
  2758. $imgfld=$_CONF['path_html'].$box_conf['imgfile_frd'];
  2759. if ( $box_conf['imgfile_subdir']==1){
  2760. $imgfld.=$addition_def[$field_id]['templatesetvar'];
  2761. }
  2762. $imgfld_thmb=$_CONF['path_html'].$box_conf['imgfile_thumb_frd'];
  2763. if ( $box_conf['imgfile_subdir']==1){
  2764. $imgfld_thmb.=$addition_def[$field_id]['templatesetvar'];
  2765. }
  2766. if (!is_writable ( $imgfld )){
  2767. $rt.=$imgfld.": ".$lang_box_admin['err_writable'];
  2768. $rt.="<br ".XHTML.">".LB;
  2769. }
  2770. if ($imgfld<>$imgfld_thmb){
  2771. if (!is_writable ( $imgfld_thmb )){
  2772. $rt.=$imgfld_thmb.": ".$lang_box_admin['err_writable'] ;
  2773. $rt.="<br ".XHTML.">".LB;
  2774. }
  2775. }
  2776. if (is_array($fldary_del) AND $fldary_del[$field_id]){
  2777. //$fldary[$field_id]="";
  2778. //$fldary_fnm[$field_id]="";
  2779. }else{
  2780. if (is_array($fldary_fnm)){
  2781. $imgname=$_FILES['afield_fnm']['name'][$field_id];
  2782. $imgfile=$_FILES['afield_fnm']['tmp_name'][$field_id];
  2783. $imgsize=$_FILES['afield_fnm']['size'][$field_id];
  2784. $imgtype=$_FILES['afield_fnm']['type'][$field_id];
  2785. if ($imgfile<>""){
  2786. $imgerr="";
  2787. if ($box_conf['imgfile_size2']<>"" AND $imgsize>$box_conf['imgfile_size2']){
  2788. $rt.=$addition_def[$field_id]['name'].": ".$lang_box_admin['err_size'];
  2789. $rt.="<br ".XHTML.">".LB;
  2790. $imgerr=1;
  2791. }
  2792. if (count($box_conf['imgfile_type2'])>0){
  2793. if (in_array($imgtype,$box_conf['imgfile_type2'])){
  2794. }else{
  2795. $rt.=$addition_def[$field_id]['name'].": ".$lang_box_admin['err_type2']
  2796. .$_FILES['afield_fnm']['name'][$field_id]."(".$imgtype.")";
  2797. $rt.="<br ".XHTML.">".LB;
  2798. $imgerr=1;
  2799. }
  2800. }
  2801. //$imgname=sanitize
  2802. // 問題文字を除く
  2803. //$filename = str_replace("&","",$filename);
  2804. //$filename = str_replace("'","",$filename);
  2805. //$filename = str_replace("/","",$filename);
  2806. //$filename = str_replace(".JPG",".jpg",$filename);
  2807. //重複チェック
  2808. if ($imgerr===""){
  2809. $fldary[$field_id]=$imgname."|".fldary_alt;//@@@@@@@!!!!
  2810. }
  2811. }
  2812. }else{
  2813. }
  2814. }
  2815. }
  2816. //図 DB記憶
  2817. if ($addition_def[$field_id]['type']==11){//図
  2818. if (is_array($fldary_del) AND $fldary_del[$field_id]){
  2819. $fldary[$field_id]="";
  2820. $fldary_fnm[$field_id]="";
  2821. }else{
  2822. //$figure = $_FILES[$w];
  2823. // $imgfile=$figure[ 'tmp_name' ];
  2824. $imgfile=$_FILES['afield_fnm']['tmp_name'][$field_id];
  2825. $imgsize=$_FILES['afield_fnm']['size'][$field_id];
  2826. $imgtype=$_FILES['afield_fnm']['type'][$field_id];
  2827. if ($imgfile<>""){
  2828. $imgerr="";
  2829. if ($box_conf['imgfile_size']<>"" AND $imgsize>$box_conf['imgfile_size']){
  2830. $rt.=$addition_def[$field_id]['name'].": ".$lang_box_admin['err_size'];
  2831. $rt.="<br ".XHTML.">".LB;
  2832. $imgerr=1;
  2833. }
  2834. if (count($box_conf['imgfile_type'])>0){
  2835. if (in_array($imgtype,$box_conf['imgfile_type'])){
  2836. }else{
  2837. $rt.=$addition_def[$field_id]['name'].": ".$lang_box_admin['err_type']
  2838. .$_FILES['afield_fnm']['name'][$field_id]."(".$imgtype.")";
  2839. $rt.="<br ".XHTML.">".LB;
  2840. $imgerr=1;
  2841. }
  2842. }
  2843. if ($imgerr===""){
  2844. $imgbinary = fread ( fopen ( $imgfile , "r" ), filesize ( $imgfile ));
  2845. $fldary[$field_id]=base64_encode($imgbinary);
  2846. }
  2847. }
  2848. }
  2849. }
  2850. //日付 日時
  2851. if ($addition_def[$field_id]['type']==3 OR $addition_def[$field_id]['type']==4
  2852. OR $addition_def[$field_id]['type']==22 OR $addition_def[$field_id]['type']==23){//日付
  2853. if ($value ===""){
  2854. }else{
  2855. $w=strtotime($value);
  2856. if ($addition_def[$field_id]['range_start']==""
  2857. AND $addition_def[$field_id]['range_end']=="" ){
  2858. }else{
  2859. $w_start=strtotime($addition_def[$field_id]['range_start']);
  2860. $w_end=strtotime($addition_def[$field_id]['range_end']);
  2861. if ($w <$w_start OR $w >$w_end){
  2862. $rt.=$addition_def[$field_id]['name'].": ".$lang_box_admin['err_range']
  2863. ."(".$addition_def[$field_id]['range_start']
  2864. ."-".$addition_def[$field_id]['range_end'].")" ;
  2865. $rt.="<br ".XHTML.">".LB;
  2866. }
  2867. }
  2868. if ($w==""){
  2869. $w_chk=false;
  2870. }else{
  2871. $w_year=date('Y', $w);
  2872. $w_month=date('m', $w);
  2873. $w_day=date('d', $w);
  2874. $w_chk=checkdate($w_month, $w_day, $w_year);
  2875. }
  2876. if ($w_chk==false) {
  2877. $rt.=$addition_def[$field_id]['name'].": ".$lang_box_admin['err_date'] ;
  2878. $rt.="<br ".XHTML.">".LB;
  2879. }else{
  2880. $w_date=date("Y-m-d",$w);
  2881. if ($addition_def[$field_id]['type']==3){
  2882. $w_time="";
  2883. }else{
  2884. $w_time=date("H:i",$w)."::00";
  2885. }
  2886. $fldary[$field_id]=COM_convertDate2Timestamp($w_date,$w_time);
  2887. }
  2888. }
  2889. }
  2890. //時刻
  2891. if ($addition_def[$field_id]['type']==26){
  2892. if ($value ===""){
  2893. }else{
  2894. $w=strtotime("1970-1-1 ".$value);
  2895. if ($addition_def[$field_id]['range_start']==""
  2896. AND $addition_def[$field_id]['range_end']=="" ){
  2897. }else{
  2898. $w_start=strtotime("1970-1-1 ".$addition_def[$field_id]['range_start'].":00");
  2899. $w_end=strtotime("1970-1-1 ".$addition_def[$field_id]['range_end'].":00");
  2900. if ($w <$w_start OR $w >$w_end){
  2901. $rt.=$addition_def[$field_id]['name'].": ".$lang_box_admin['err_range']
  2902. ."(".$addition_def[$field_id]['range_start']
  2903. ."-".$addition_def[$field_id]['range_end'].")" ;
  2904. $rt.="<br ".XHTML.">".LB;
  2905. }
  2906. }
  2907. if ($w=="") {
  2908. $rt.=$addition_def[$field_id]['name'].": ".$lang_box_admin['err_time'] ;
  2909. $rt.="<br ".XHTML.">".LB;
  2910. }else{
  2911. $w_time=date("H:i",$w)."::00";
  2912. $fldary[$field_id]=COM_convertDate2Timestamp("1970-1-1",$w_time);
  2913. }
  2914. }
  2915. }
  2916. //メールアドレス
  2917. if ($addition_def[$field_id]['type']==5){
  2918. if ($value ===""){
  2919. }else{
  2920. if (COM_isEmail ($value)==false) {
  2921. $rt.=$addition_def[$field_id]['name'].$LANG04[18];
  2922. $rt.="<br ".XHTML.">".LB;
  2923. }
  2924. }
  2925. }
  2926. //url
  2927. if ($addition_def[$field_id]['type']==6){
  2928. if ($value ===""){
  2929. }else{
  2930. if (preg_match('/^(https?|ftp)(:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)$/', $value)) {
  2931. } else {
  2932. $rt.=$addition_def[$field_id]['name'].": ".$lang_box_admin['err_url'];
  2933. $rt.="<br ".XHTML.">".LB;
  2934. }
  2935. }
  2936. }
  2937. //numeric
  2938. if ($addition_def[$field_id]['type']==15 OR $addition_def[$field_id]['type']==21){
  2939. if ($value ===""){
  2940. }else{
  2941. if (is_numeric($value)) {
  2942. } else {
  2943. $rt.=$addition_def[$field_id]['name'].": ".$lang_box_admin['err_numeric'];
  2944. $rt.="<br ".XHTML.">".LB;
  2945. }
  2946. }
  2947. }
  2948. //text field
  2949. if (($addition_def[$field_id]['type']==0)
  2950. OR ($addition_def[$field_id]['type']==1)
  2951. OR ($addition_def[$field_id]['type']==10) ){
  2952. if ($value ===""){
  2953. }else{
  2954. if ($addition_def[$field_id]['textcheck']==11){ //'半角数字のみ';
  2955. if (!preg_match("/^[0-9]+$/", $value)){
  2956. $rt.=$addition_def[$field_id]['name'].": ".$lang_box_admin['err_text1'];
  2957. $rt.="<br ".XHTML.">".LB;
  2958. }
  2959. }else if ($addition_def[$field_id]['textcheck']==12){//半角英数字のみ';
  2960. if (!preg_match("/^[a-zA-Z0-9]+$/", $value)){
  2961. $rt.=$addition_def[$field_id]['name'].": ".$lang_box_admin['err_text2'];
  2962. $rt.="<br ".XHTML.">".LB;
  2963. }
  2964. }else if ($addition_def[$field_id]['textcheck']==13){//標準IDの範囲内';
  2965. $value=rtrim(ltrim($value));
  2966. $newvalue=COM_sanitizeID($value);
  2967. if ($value<>$newvalue){
  2968. $rt.=$addition_def[$field_id]['name'].": ".$lang_box_admin['err_text3'];
  2969. $rt.="<br ".XHTML.">".LB;
  2970. }
  2971. $fldary[$field_id]=$value;
  2972. }else if ($addition_def[$field_id]['textcheck']==14){//半角英数字記号のみ';
  2973. if (!preg_match("/^[!-~]+$/", $value)){
  2974. $rt.=$addition_def[$field_id]['name'].": ".$lang_box_admin['err_text4'];
  2975. $rt.="<br ".XHTML.">".LB;
  2976. }
  2977. }
  2978. }
  2979. }
  2980. //textarea
  2981. if ($addition_def[$field_id]['type']==1
  2982. OR $addition_def[$field_id]['type']==10
  2983. OR $addition_def[$field_id]['type']==20
  2984. ){
  2985. if ($value ===""){
  2986. }else{
  2987. if (mb_strlen($value, 'UTF-8')>$addition_def[$field_id]['maxlength']) {
  2988. $rt.=$addition_def[$field_id]['name']
  2989. .$addition_def[$field_id]['maxlength']
  2990. .": ".$lang_box_admin['err_maxlength'];
  2991. $rt.="<br ".XHTML.">".LB;
  2992. }
  2993. }
  2994. }
  2995. //添付ファイル
  2996. if ($addition_def[$field_id]['type']==13){
  2997. $file_path=$box_conf['file_path'];
  2998. if ( $box_conf['file_subdir']==1){
  2999. $file_path.=$addition_def[$field_id]['templatesetvar'];
  3000. }
  3001. if (!is_writable ( $file_path )){
  3002. $rt.=$file_path.": ".$lang_box_admin['err_writable'];
  3003. $rt.="<br ".XHTML.">".LB;
  3004. }
  3005. if (is_array($fldary_del) AND $fldary_del[$field_id]){
  3006. }else{
  3007. if (is_array($fldary_fnm)){
  3008. $filename=$_FILES['afield_fnm']['name'][$field_id];
  3009. $filetmpname=$_FILES['afield_fnm']['tmp_name'][$field_id];
  3010. $filesize=$_FILES['afield_fnm']['size'][$field_id];
  3011. $filetype=$_FILES['afield_fnm']['type'][$field_id];
  3012. if ($filetmpname<>""){
  3013. $err="";
  3014. if ($box_conf['file_size']<>"" AND $filesize>$box_conf['file_size']){
  3015. $rt.=$addition_def[$field_id]['name'].": ".$lang_box_admin['err_size'];
  3016. $rt.="<br ".XHTML.">".LB;
  3017. $err=1;
  3018. }
  3019. if (count($box_conf['file_type'])>0){
  3020. if (in_array($filetype,$box_conf['file_type'])){
  3021. }else{
  3022. $rt.=$addition_def[$field_id]['name'].": ".$lang_box_admin['err_type']
  3023. .$_FILES['afield_fnm']['name'][$field_id]."(".$filetype.")";
  3024. $rt.="<br ".XHTML.">".LB;
  3025. $err=1;
  3026. }
  3027. }
  3028. //チェックOK
  3029. if ($err===""){
  3030. $fldary[$field_id]=$filename;
  3031. }
  3032. }
  3033. }else{
  3034. }
  3035. }
  3036. }
  3037. //range check 範囲チェック
  3038. if ($addition_def[$field_id]['range_start']=="" AND $addition_def[$field_id]['range_end']=="" ){
  3039. }else{
  3040. if (($addition_def[$field_id]['type']==0)
  3041. OR ($addition_def[$field_id]['type']==1)
  3042. OR ($addition_def[$field_id]['type']==15)
  3043. OR ($addition_def[$field_id]['type']==21) ){
  3044. if ($value <$addition_def[$field_id]['range_start']
  3045. OR $value >$addition_def[$field_id]['range_end']){
  3046. $rt.=$addition_def[$field_id]['name'].": ".$lang_box_admin['err_range']
  3047. ."(".$addition_def[$field_id]['range_start']
  3048. ."-".$addition_def[$field_id]['range_end'].")";
  3049. $rt.="<br ".XHTML.">".LB;
  3050. }
  3051. }
  3052. }
  3053. }
  3054. }
  3055. return $rt;
  3056. }
  3057. function DATABOX_uploadaddtiondatas(
  3058. &$fldary
  3059. ,$addition_def
  3060. ,$pi_name
  3061. ,$id
  3062. ,$fldary_fnm=""
  3063. ,$fldary_del=""
  3064. ,$fldary_old=""
  3065. ,$fldary_alt=""
  3066. )
  3067. // +---------------------------------------------------------------------------+
  3068. // | 機能 追加項目upload
  3069. // | 書式 DATABOX_uploadaddtiondatas($additionfields,$addition_def,$pi_name
  3070. // | ,$additionfields_fnm,$additionfields_del)
  3071. // +---------------------------------------------------------------------------+
  3072. // | 引数 $fldary:追加項目データ配列
  3073. // | 引数 $addition_def:追加項目定義
  3074. // | 引数 $pi_name: 'databox' 'userbox' 'formbox'
  3075. // +-----
  3076. // | 引数 $fldary_fnm:追加項目データ配列 アップロードファイル名
  3077. // | 引数 $fldary_del:追加項目データ配列 アップロードファイル削除
  3078. // | 引数 $fldary_old:追加項目データ配列 OLD
  3079. // +---------------------------------------------------------------------------+
  3080. // | 戻値 nomal:
  3081. // +---------------------------------------------------------------------------+
  3082. //update
  3083. {
  3084. global $_CONF;
  3085. global $LANG04;
  3086. global $_FILES;
  3087. $lang_box_admin="LANG_".strtoupper($pi_name)."_ADMIN";
  3088. global $$lang_box_admin;
  3089. $lang_box_admin=$$lang_box_admin;
  3090. $box_conf="_".strtoupper($pi_name)."_CONF";
  3091. global $$box_conf;
  3092. $box_conf=$$box_conf;
  3093. $rt="";
  3094. if (is_array($fldary)){
  3095. foreach( $fldary as $field_id => $value ){
  3096. //図 外記憶
  3097. if ($addition_def[$field_id]['type']==12){//図
  3098. $imgfld=$_CONF['path_html'].$box_conf['imgfile_frd'];
  3099. $imgfld_thmb=$_CONF['path_html'].$box_conf['imgfile_thumb_frd'];
  3100. $filename=$fldary[$field_id];
  3101. $a=explode("|",$fldary[$field_id]);
  3102. $filename=$a[0];
  3103. $a=explode("|",$fldary_old[$field_id]);
  3104. $filename_old=$a[0];
  3105. if (is_array($fldary_del) AND $fldary_del[$field_id]){
  3106. $rt=DATABOX_deleteFile($imgfld.$filename);
  3107. $thumbname=DATABOX_getthumbname($filename);
  3108. $rt=DATABOX_deleteFile($imgfld_thmb.$thumbname);
  3109. $fldary[$field_id]="";
  3110. }else{
  3111. $imgname=$_FILES['afield_fnm']['name'][$field_id];
  3112. if ($imgname<>""){
  3113. if ($filename_old<>""){
  3114. $rt=DATABOX_deleteFile($imgfld.$filename_old);
  3115. $thumbname=DATABOX_getthumbname($filename_old);
  3116. $rt=DATABOX_deleteFile($imgfld_thmb.$thumbname);
  3117. }
  3118. $imgfile=$_FILES['afield_fnm']['tmp_name'][$field_id];
  3119. $imgsize=$_FILES['afield_fnm']['size'][$field_id];
  3120. $imgtype=$_FILES['afield_fnm']['type'][$field_id];
  3121. $a=explode(".",$imgname);
  3122. $a[1]=strtolower($a[1]);
  3123. if ( $box_conf['imgfile_subdir']==1){
  3124. $newfilename=$addition_def[$field_id]['templatesetvar']."/";
  3125. }else{
  3126. $newfilename="";
  3127. }
  3128. $newfilename.=$addition_def[$field_id]['templatesetvar']."_".$id."_".time().".".$a[1];
  3129. //$newfilename=$imgname;
  3130. if (DATABOX_uploadImageFile
  3131. ($imgname,$imgfile,$imgsize, $imgtype,$imgfld,$newfilename)){
  3132. $fldary[$field_id]=$newfilename."|".$fldary_alt[$field_id];//@@@@@@@!!!!
  3133. //サムネイル作成する場合
  3134. if($box_conf['imgfile_thumb_ok'] && function_exists('ImageCreate')) {
  3135. $rt=DATABOX_createthumb(
  3136. $newfilename
  3137. ,$box_conf['imgfile_thumb_w'] ,$box_conf['imgfile_thumb_h']
  3138. ,$box_conf['imgfile_thumb_w2'] ,$box_conf['imgfile_thumb_h2']
  3139. ,$imgfld_thmb,$imgfld);
  3140. }
  3141. }else{
  3142. $fldary[$field_id]="";
  3143. //$fldary_fnm[$field_id]="";
  3144. }
  3145. }
  3146. }
  3147. }
  3148. //添付ファイル
  3149. if ($addition_def[$field_id]['type']==13){
  3150. $imgfld=$box_conf['file_path'];
  3151. $filename=$fldary[$field_id];
  3152. $a=explode("|",$fldary_old[$field_id]);
  3153. $filename_old=$a[0];
  3154. if (is_array($fldary_del) AND $fldary_del[$field_id]){
  3155. $rt=DATABOX_deleteFile($imgfld.$filename_old);
  3156. $fldary[$field_id]="";
  3157. }else{
  3158. $imgname=$_FILES['afield_fnm']['name'][$field_id];
  3159. if ($imgname<>""){
  3160. if ($filename_old<>""){
  3161. $rt=DATABOX_deleteFile($imgfld.$filename_old);
  3162. }
  3163. $imgfile=$_FILES['afield_fnm']['tmp_name'][$field_id];
  3164. $imgsize=$_FILES['afield_fnm']['size'][$field_id];
  3165. $imgtype=$_FILES['afield_fnm']['type'][$field_id];
  3166. $a=explode(".",$imgname);
  3167. $a[1]=strtolower($a[1]);//拡張子を小文字にする
  3168. if ( $box_conf['file_subdir']==1){
  3169. $newfilename=$addition_def[$field_id]['templatesetvar']."/";
  3170. }else{
  3171. $newfilename="";
  3172. }
  3173. $newfilename.=$addition_def[$field_id]['templatesetvar']."_".$id."_".time().".".$a[1];
  3174. if (DATABOX_uploadImageFile
  3175. ($imgname,$imgfile,$imgsize, $imgtype,$imgfld,$newfilename)){
  3176. $fldary[$field_id]=$newfilename."|".$imgname;
  3177. }else{
  3178. $fldary[$field_id]="";
  3179. }
  3180. }
  3181. }
  3182. }
  3183. }
  3184. }
  3185. return $rt;
  3186. }
  3187. function DATABOX_uploadaddtiondatas_cpy(
  3188. &$fldary
  3189. ,$addition_def
  3190. ,$pi_name
  3191. ,$id
  3192. ,$fldary_fnm=""
  3193. ,$fldary_del=""
  3194. ,$fldary_old=""
  3195. ,$fldary_alt=""
  3196. )
  3197. // +---------------------------------------------------------------------------+
  3198. // | 機能 追加項目upload for copy
  3199. // | 書式 DATABOX_uploadaddtiondatas($additionfields,$addition_def,$pi_name
  3200. // | ,$additionfields_fnm,$additionfields_del)
  3201. // +---------------------------------------------------------------------------+
  3202. // | 引数 $fldary:追加項目データ配列
  3203. // | 引数 $addition_def:追加項目定義
  3204. // | 引数 $pi_name: 'databox' 'userbox' 'formbox'
  3205. // +-----
  3206. // | 引数 $fldary_fnm:追加項目データ配列 アップロードファイル名
  3207. // | 引数 $fldary_del:追加項目データ配列 アップロードファイル削除
  3208. // | 引数 $fldary_old:追加項目データ配列 OLD
  3209. // +---------------------------------------------------------------------------+
  3210. // | 戻値 nomal:
  3211. // +---------------------------------------------------------------------------+
  3212. //update
  3213. {
  3214. global $_CONF;
  3215. global $LANG04;
  3216. global $_FILES;
  3217. $lang_box_admin="LANG_".strtoupper($pi_name)."_ADMIN";
  3218. global $$lang_box_admin;
  3219. $lang_box_admin=$$lang_box_admin;
  3220. $box_conf="_".strtoupper($pi_name)."_CONF";
  3221. global $$box_conf;
  3222. $box_conf=$$box_conf;
  3223. $rt="";
  3224. if (is_array($fldary)){
  3225. foreach( $fldary as $field_id => $value ){
  3226. //図 外記憶
  3227. if ($addition_def[$field_id]['type']==12){//図
  3228. $imgfld=$_CONF['path_html'].$box_conf['imgfile_frd'];
  3229. $imgfld_thmb=$_CONF['path_html'].$box_conf['imgfile_thumb_frd'];
  3230. //$filename=$fldary[$field_id];
  3231. //$filename_old=$fldary_old[$field_id];
  3232. $a=explode("|",$fldary[$field_id]);
  3233. $filename=$a[0];//ファイル名
  3234. $a=explode("|",$fldary_old[$field_id]);
  3235. $filename_old=$a[0];//ファイル名
  3236. if (is_array($fldary_del) AND $fldary_del[$field_id]){
  3237. $fldary[$field_id]="";
  3238. }else{
  3239. $imgname=$_FILES['afield_fnm']['name'][$field_id];
  3240. if ($imgname<>""){
  3241. $imgfile=$_FILES['afield_fnm']['tmp_name'][$field_id];
  3242. $imgsize=$_FILES['afield_fnm']['size'][$field_id];
  3243. $imgtype=$_FILES['afield_fnm']['type'][$field_id];
  3244. $a=explode(".",$imgname);
  3245. $a[1]=strtolower($a[1]);
  3246. if ( $box_conf['imgfile_subdir']==1){
  3247. $newfilename=$addition_def[$field_id]['templatesetvar']."/";
  3248. }else{
  3249. $newfilename="";
  3250. }
  3251. $newfilename.=$addition_def[$field_id]['templatesetvar']."_".$id."_".time().".".$a[1];
  3252. //$newfilename=$imgname;
  3253. if (DATABOX_uploadImageFile
  3254. ($imgname,$imgfile,$imgsize, $imgtype,$imgfld,$newfilename)){
  3255. $fldary[$field_id]=$newfilename."|".$fldary_alt[$field_id];
  3256. //サムネイル作成する場合
  3257. if($box_conf['imgfile_thumb_ok'] && function_exists('ImageCreate')) {
  3258. $rt=DATABOX_createthumb(
  3259. $newfilename
  3260. ,$box_conf['imgfile_thumb_w'] ,$box_conf['imgfile_thumb_h']
  3261. ,$box_conf['imgfile_thumb_w2'] ,$box_conf['imgfile_thumb_h2']
  3262. ,$imgfld_thmb,$imgfld);
  3263. }
  3264. }else{
  3265. $fldary[$field_id]="";
  3266. }
  3267. }else{
  3268. if ($filename_old<>""){
  3269. $cpyfrom=$imgfld.$filename_old;
  3270. $a=explode(".",$filename_old);
  3271. $a[1]=strtolower($a[1]);
  3272. if ( $box_conf['imgfile_subdir']==1){
  3273. $newfilename=$addition_def[$field_id]['templatesetvar']."/";
  3274. }else{
  3275. $newfilename="";
  3276. }
  3277. $newfilename.=$addition_def[$field_id]['templatesetvar']."_".$id."_".time().".".$a[1];
  3278. $cpyto=$imgfld.$newfilename;
  3279. $rt=copy( $cpyfrom, $cpyto );
  3280. //
  3281. $thumbname=DATABOX_getthumbname($filename_old);
  3282. $cpyfrom =$imgfld_thmb.$thumbname;
  3283. $thumbname=DATABOX_getthumbname($newfilename);
  3284. $cpyto =$imgfld_thmb.$thumbname;
  3285. $rt=copy( $cpyfrom, $cpyto );
  3286. //
  3287. $fldary[$field_id]=$newfilename."|".$fldary_alt[$field_id];
  3288. }
  3289. }
  3290. }
  3291. }
  3292. //添付ファイル
  3293. if ($addition_def[$field_id]['type']==13){
  3294. $imgfld=$box_conf['file_path'];
  3295. $filename=$fldary[$field_id];
  3296. $a=explode("|",$fldary_old[$field_id]);
  3297. $filename_old=$a[0];
  3298. $imgname_old=$a[1];
  3299. if (is_array($fldary_del) AND $fldary_del[$field_id]){
  3300. $fldary[$field_id]="";
  3301. }else{
  3302. $imgname=$_FILES['afield_fnm']['name'][$field_id];
  3303. if ($imgname<>""){
  3304. $imgfile=$_FILES['afield_fnm']['tmp_name'][$field_id];
  3305. $imgsize=$_FILES['afield_fnm']['size'][$field_id];
  3306. $imgtype=$_FILES['afield_fnm']['type'][$field_id];
  3307. $a=explode(".",$imgname);
  3308. $a[1]=strtolower($a[1]);
  3309. if ( $box_conf['imgfile_subdir']==1){
  3310. $newfilename=$addition_def[$field_id]['templatesetvar']."/";
  3311. }else{
  3312. $newfilename="";
  3313. }
  3314. $newfilename.=$addition_def[$field_id]['templatesetvar']."_".$id."_".time().".".$a[1];
  3315. if (DATABOX_uploadImageFile
  3316. ($imgname,$imgfile,$imgsize, $imgtype,$imgfld,$newfilename)){
  3317. $fldary[$field_id]=$newfilename;
  3318. }else{
  3319. $fldary[$field_id]="";
  3320. }
  3321. }else{
  3322. if ($filename_old<>""){
  3323. $cpyfrom=$imgfld.$filename_old;
  3324. $a=explode(".",$filename_old);
  3325. $a[1]=strtolower($a[1]);
  3326. if ( $box_conf['file_subdir']==1){
  3327. $newfilename=$addition_def[$field_id]['templatesetvar']."/";
  3328. }else{
  3329. $newfilename="";
  3330. }
  3331. $newfilename.=$addition_def[$field_id]['templatesetvar']."_".$id."_".time().".".$a[1];
  3332. $cpyto=$imgfld.$newfilename;
  3333. $rt=copy( $cpyfrom, $cpyto );
  3334. //
  3335. $fldary[$field_id]=$newfilename."|".$imgname_old;
  3336. }
  3337. }
  3338. }
  3339. }
  3340. }
  3341. }
  3342. return $rt;
  3343. }
  3344. //update
  3345. function DATABOX_uploadaddtiondatas_xml(
  3346. &$fldary
  3347. ,$addition_def
  3348. ,$pi_name
  3349. ,$id
  3350. )
  3351. {
  3352. global $_CONF;
  3353. global $LANG04;
  3354. global $_FILES;
  3355. $lang_box_admin="LANG_".strtoupper($pi_name)."_ADMIN";
  3356. global $$lang_box_admin;
  3357. $lang_box_admin=$$lang_box_admin;
  3358. $box_conf="_".strtoupper($pi_name)."_CONF";
  3359. global $$box_conf;
  3360. $box_conf=$$box_conf;
  3361. $rt="";
  3362. if (is_array($fldary)){
  3363. foreach( $fldary as $field_id => $value ){
  3364. if ($fldary[$field_id]<>""){
  3365. //図 外記憶
  3366. if ($addition_def[$field_id]['type']==12){//図
  3367. $imgfld=$_CONF['path_html'].$box_conf['imgfile_frd'];
  3368. $imgfld_thmb=$_CONF['path_html'].$box_conf['imgfile_thumb_frd'];
  3369. //
  3370. if ($box_conf['imgfile_subdir']==1){
  3371. $imgname=$addition_def[$field_id]['templatesetvar']."/";
  3372. }
  3373. $imgname.=$addition_def[$field_id]['templatesetvar']."_".$id."_".time().".jpg";
  3374. $imgsrc=$fldary[$field_id];
  3375. if (DATABOX_uploadImageFile_xml($imgname,$imgsrc,$imgfld)){
  3376. $fldary[$field_id]=$imgname;
  3377. //サムネイル作成する場合
  3378. if($box_conf['imgfile_thumb_ok']==="1" && function_exists('ImageCreate')) {
  3379. $srcfile=$imgfld.$imgname;
  3380. $rt=DATABOX_createthumb(
  3381. $imgname
  3382. ,$box_conf['imgfile_thumb_w'] ,$box_conf['imgfile_thumb_h']
  3383. ,$box_conf['imgfile_thumb_w2'] ,$box_conf['imgfile_thumb_h2']
  3384. ,$imgfld_thmb,$imgfld);
  3385. }
  3386. }else{
  3387. $fldary[$field_id]="";
  3388. }
  3389. }
  3390. }
  3391. }
  3392. }
  3393. return $rt;
  3394. }
  3395. function DATABOX_deleteaddtionfiles(
  3396. $fldary
  3397. ,$addition_def
  3398. ,$pi_name
  3399. ){
  3400. global $_CONF;
  3401. $box_conf="_".strtoupper($pi_name)."_CONF";
  3402. global $$box_conf;
  3403. $box_conf=$$box_conf;
  3404. $rt="";
  3405. if (is_array($fldary)){
  3406. foreach( $fldary as $field_id => $value ){
  3407. //図 外記憶
  3408. if ($addition_def[$field_id]['type']==12){//図
  3409. $a=explode("|",$fldary[$field_id]);
  3410. $filename=$a[0];
  3411. if ($filename<>""){
  3412. $imgfld=$_CONF['path_html'].$box_conf['imgfile_frd'];
  3413. $imgfld_thmb=$_CONF['path_html'].$box_conf['imgfile_thumb_frd'];
  3414. $rt=DATABOX_deleteFile($imgfld.$filename);
  3415. $thumbname=DATABOX_getthumbname($filename);
  3416. $rt=DATABOX_deleteFile($imgfld_thmb.$thumbname);
  3417. }
  3418. }
  3419. //添付ファイル
  3420. if ($addition_def[$field_id]['type']==13){
  3421. $imgfld=$box_conf['file_path'];
  3422. $a=explode("|",$fldary[$field_id]);
  3423. $filename=$a[0];
  3424. if ($filename<>""){
  3425. $rt=DATABOX_deleteFile($imgfld.$filename);
  3426. }
  3427. }
  3428. }
  3429. }
  3430. return $rt;
  3431. }
  3432. //
  3433. function DATABOX_deleteaddtionfiles_def(
  3434. $field_id
  3435. ,$pi_name
  3436. ){
  3437. global $_CONF;
  3438. global $_TABLES;
  3439. $box_conf="_".strtoupper($pi_name)."_CONF";
  3440. global $$box_conf;
  3441. $box_conf=$$box_conf;
  3442. $rt="";
  3443. $table_addition=$_TABLES[strtoupper($pi_name).'_addition'];
  3444. //
  3445. $sql="SELECT value ";
  3446. $sql.=" FROM";
  3447. $sql.=" {$table_addition} ";
  3448. $sql.=" where";
  3449. $sql.=" field_id=".$field_id;
  3450. $result = DB_query ($sql);
  3451. $numrows = DB_numRows ($result);
  3452. for ($i = 1; $i <= $numrows; $i++) {
  3453. $A = DB_fetchArray ($result);
  3454. $filename = COM_stripslashes($A['value']);
  3455. if ($filename<>""){
  3456. $imgfld=$_CONF['path_html'].$box_conf['imgfile_frd'];
  3457. $imgfld_thmb=$_CONF['path_html'].$box_conf['imgfile_thumb_frd'];
  3458. $rt=DATABOX_deleteFile($imgfld.$filename);
  3459. $thumbname=DATABOX_getthumbname($filename);
  3460. $rt=DATABOX_deleteFile($imgfld_thmb.$thumbname);
  3461. }
  3462. }
  3463. return $rt;
  3464. }
  3465. function DATABOX_deleteaddtionfiles_all(
  3466. $fld
  3467. ,$pi_name
  3468. ){
  3469. global $_CONF;
  3470. global $_TABLES;
  3471. $box_conf="_".strtoupper($pi_name)."_CONF";
  3472. global $$box_conf;
  3473. $box_conf=$$box_conf;
  3474. $rt="";
  3475. if( is_dir( $fld)){
  3476. $fd = opendir( $fld );
  3477. while(( $file = @readdir( $fd )) == TRUE ) {
  3478. if( !is_dir( $fd1 . $file)
  3479. && $dir <> '.'
  3480. && $dir <> '..'
  3481. && $dir <> 'CVS'
  3482. && substr( $dir, 0 , 1 ) <> '.' ) {
  3483. clearstatcache();
  3484. $rt=DATABOX_deleteFile($fld.$file);
  3485. }
  3486. }
  3487. }
  3488. return $rt;
  3489. }
  3490. // +---------------------------------------------------------------------------+
  3491. // | 機能 追加項目uploadfile delete
  3492. // | 書式 DATABOX_checkdditiondatas($filename)
  3493. // +---------------------------------------------------------------------------+
  3494. // | 引数 $filename:フォルダ/ファイル
  3495. // +---------------------------------------------------------------------------+
  3496. // | 戻値 nomal:
  3497. // +---------------------------------------------------------------------------+
  3498. //update
  3499. function DATABOX_deleteFile (
  3500. $filename
  3501. )
  3502. {
  3503. $rt=false;
  3504. if (file_exists ($filename)) {
  3505. if (!@unlink ($filename)) {
  3506. COM_errorLog ("Unable to remove file $filename");
  3507. }else{
  3508. $rt=true;
  3509. COM_errorLog ("remove file $filename");
  3510. }
  3511. }else{
  3512. COM_errorLog ("Unable to remove file $filename not exist");
  3513. }
  3514. return $rt;
  3515. }
  3516. function DATABOX_uploadImageFile (
  3517. $imgname
  3518. ,$imgfile
  3519. ,$imgsize
  3520. ,$imgtype
  3521. ,$imgfld
  3522. ,$newfilename
  3523. )
  3524. // +---------------------------------------------------------------------------+
  3525. // | 機能 upload Image File
  3526. // | 書式 DATABOX_uploadImageFile($imgname,$imgfile,$imgsize, $imgtype,$imgfld)
  3527. // +---------------------------------------------------------------------------+
  3528. // | 引数 $imgname:
  3529. // | 引数 $imgfile:
  3530. // | 引数 $imgsize:
  3531. // | 引数 $imgtype:
  3532. // | 引数 $imgfld:
  3533. // +---------------------------------------------------------------------------+
  3534. // | 戻値 nomal:
  3535. // +---------------------------------------------------------------------------+
  3536. //update
  3537. {
  3538. $FilePermissions = (int) 0755;
  3539. if (is_uploaded_file ($imgfile)) {
  3540. //$newfile=$imgfld.$imgname;
  3541. $newfile=$imgfld.$newfilename;
  3542. if(!file_exists($newfile)) {
  3543. $returnMove = move_uploaded_file($imgfile, $newfile);
  3544. if (!$returnMove) {
  3545. $logmsg="DataBox File upload error: ".$tmp." to ".$name;
  3546. COM_errorLOG($logmsg);
  3547. return false;
  3548. } else {
  3549. $chown =@chmod ($newfile,$FilePermissions);
  3550. $logmsg="DataBox File upload sucsess: ".$imgname;
  3551. COM_errorLOG($logmsg);
  3552. return true;
  3553. }
  3554. }else{
  3555. COM_errorLOG("DataBox upload error: Temporary file does not exist: '".$tmp ."'");
  3556. return false;
  3557. }
  3558. }
  3559. }
  3560. //
  3561. function DATABOX_uploadImageFile_xml (
  3562. $imgname
  3563. ,$imgsrc
  3564. ,$imgfld
  3565. )
  3566. {
  3567. $FilePermissions = (int) 0755;
  3568. $newfile=$imgfld.$imgname;
  3569. //
  3570. $fp = fopen($newfile, "w");
  3571. $imgsrc=base64_decode($imgsrc);
  3572. fputs($fp, $imgsrc);
  3573. fclose($fp);
  3574. if(!file_exists($newfile)) {
  3575. $logmsg="DataBox ImageFile upload error: ".$tmp." to ".$name;
  3576. COM_errorLOG($logmsg);
  3577. return false;
  3578. } else {
  3579. $chown =@chmod ($newfile,$FilePermissions);
  3580. $logmsg="DataBox ImageFile upload sucsess: ".$imgname;
  3581. COM_errorLOG($logmsg);
  3582. return true;
  3583. }
  3584. }
  3585. function DATABOX_createthumb(
  3586. $filename
  3587. , $W
  3588. , $H
  3589. , $W2
  3590. , $H2
  3591. , $imgfld_thmb
  3592. , $imgfld
  3593. )
  3594. // +---------------------------------------------------------------------------+
  3595. // | 機能 uploadfile サムネイル作成
  3596. // | 書式 DATABOX_createthumb($srcfile,$W,$H,$W2,$H2, $thumb_dir,$tmp_dir)
  3597. // +---------------------------------------------------------------------------+
  3598. // | 引数 $imgname:
  3599. // | 引数 $imgfile:
  3600. // | 引数 $imgsize:
  3601. // | 引数 $imgtype:
  3602. // | 引数 $imgfld:
  3603. // +---------------------------------------------------------------------------+
  3604. // | 戻値 nomal:
  3605. // +---------------------------------------------------------------------------+
  3606. //update
  3607. {
  3608. //$filename = substr($srcfile, strrpos($srcfile,"/")+1);
  3609. $srcfile=$imgfld.$filename;
  3610. // 画像の幅と高さとタイプを取得
  3611. $imagesize = GetImageSize($srcfile);
  3612. $srcfile_w=$imagesize['0'];
  3613. $srcfile_h=$imagesize['1'];
  3614. $srcfile_type=$imagesize['2'];
  3615. //対象タイプの確認
  3616. switch ($srcfile_type) {
  3617. case 1 : //gif
  3618. return false;
  3619. break;
  3620. case 2 : //jpg
  3621. $srcimage = @ImageCreateFromJPEG($srcfile);
  3622. break;
  3623. case 3 : //png
  3624. $srcimage = @ImageCreateFromPNG($srcfile);
  3625. break;
  3626. }
  3627. if (!$srcimage) {
  3628. return false;
  3629. }
  3630. $logmsg="size=(w)".$srcfile_w." > ".$w." (h)".$srcfile_h." > ".$h;
  3631. COM_errorLog ($logmsg);
  3632. //対象サイズの確認
  3633. if ($srcfile_w > $w || $srcfile_h > $h) {
  3634. }else{
  3635. return false;
  3636. }
  3637. // リサイズ
  3638. if ($srcfile_w > $W || $srcfile_h > $H) {
  3639. $key_w = $W / $srcfile_w;
  3640. $key_h = $H / $srcfile_h;
  3641. ($key_w < $key_h) ? $keys = $key_w : $keys = $key_h;
  3642. $out_w = $srcfile_w * $keys;
  3643. $out_h = $srcfile_h * $keys;
  3644. } else {
  3645. $out_w = $srcfile_w;
  3646. $out_h = $srcfile_h;
  3647. }
  3648. // 出力画像(サムネイル)のイメージを作成し、元画像をコピーします。(GD2.0用)
  3649. $outimage = ImageCreateTrueColor($out_w, $out_h);
  3650. $resize = ImageCopyResampled(
  3651. $outimage, $srcimage, 0, 0, 0, 0
  3652. , $out_w, $out_h, $srcfile_w, $srcfile_h);
  3653. // サムネイル画像をブラウザに出力、保存
  3654. //$filename = substr($srcfile, strrpos($srcfile,"/")+1);
  3655. $thum_filename = DATABOX_getthumbname($filename);
  3656. $filename = substr($filename, 0, strrpos($filename,"."));
  3657. touch($imgfld_thmb.$thum_filename);
  3658. ImageJPEG($outimage, $imgfld_thmb.$thum_filename);
  3659. // 出力画像のイメージを作成し、元画像をコピーします。(GD2.0用)
  3660. // リンク先のサイズが設定値より大きい時リンク先も縮小する<-----
  3661. if ($srcfile_w > $W2 || $srcfile_h > $H2) {
  3662. $rt = rename($imgfld.$filename.".jpg",$imgfld.$filename."-bak.jpg");
  3663. if (!$rt) {
  3664. echo "rename err!";
  3665. }
  3666. $key_w = $W2 / $srcfile_w;
  3667. $key_h = $H2 / $srcfile_h;
  3668. ($key_w < $key_h) ? $keys = $key_w : $keys = $key_h;
  3669. $out_w = $srcfile_w * $keys;
  3670. $out_h = $srcfile_h * $keys;
  3671. $outimage2 = ImageCreateTrueColor($out_w, $out_h);
  3672. $resize = ImageCopyResampled(
  3673. $outimage2, $srcimage, 0, 0, 0, 0
  3674. , $out_w, $out_h, $srcfile_w, $srcfile_h);
  3675. touch($imgfld.$filename.".jpg");
  3676. ImageJPEG($outimage2, $imgfld.$filename.".jpg");
  3677. ImageDestroy($outimage2);
  3678. $rt=unlink($imgfld.$filename."-bak.jpg");
  3679. if (!$rt) {
  3680. echo "delete err!";
  3681. }
  3682. }
  3683. // 作成したイメージを破棄
  3684. ImageDestroy($srcimage);
  3685. ImageDestroy($outimage);
  3686. return $thum_filename;
  3687. }
  3688. //
  3689. function DATABOX_getthumbname(
  3690. $filename
  3691. )
  3692. {
  3693. $rt="";
  3694. if ($filename<>""){
  3695. $filename = substr($filename, 0, strrpos($filename,"."));
  3696. $rt = $filename . "-small.jpg";
  3697. }
  3698. return $rt;
  3699. }
  3700. //==============================================================================
  3701. function DATABOX_getradiolist(
  3702. $ary
  3703. ,$fld
  3704. ,$selected = 0
  3705. ,$br=""
  3706. ,$disabled=""
  3707. )
  3708. // +---------------------------------------------------------------------------+
  3709. // | 機能 ラジヲボタン作成
  3710. // | 書式 DATABOX_getradiolist
  3711. // | ($lang_noyes,"afield[".$fid."]",$fvalue,$br ,$disabled);
  3712. // +---------------------------------------------------------------------------+
  3713. // | 引数 $ary:値配列
  3714. // | 引数 $fld:field name
  3715. // | 引数 $selected:選択値 省略時
  3716. // | 引数 $br:blank 0 改行しない 1〜9 指定数毎に改行
  3717. // | 引数 $disabled:
  3718. // +---------------------------------------------------------------------------+
  3719. // | 戻値 nomal:ラジヲボタン |
  3720. // +---------------------------------------------------------------------------+
  3721. //update 20130704
  3722. {
  3723. $retval = '';
  3724. if ($br==="" ) {
  3725. $br=0;
  3726. }
  3727. $cnt=0;
  3728. foreach( $ary as $id => $value ){
  3729. //echo "ary".$i."=".$ary[$i]."<br>";
  3730. $retval .= "<input type='radio' NAME='$fld' $disabled VALUE='$id'";
  3731. if ($selected==""){
  3732. }else{
  3733. if( $id == $selected ){
  3734. $retval .= " CHECKED=CHECKED ";
  3735. }
  3736. }
  3737. $retval .= ">$ary[$id]&nbsp";
  3738. if ($br<>0){
  3739. $cnt++;
  3740. if ($cnt==$br){
  3741. $retval .="<br".XHTML.">";
  3742. $cnt=0;
  3743. }
  3744. }
  3745. }
  3746. return $retval;
  3747. }
  3748. function DATABOX_getoptionlistary(
  3749. $ary
  3750. ,$fld
  3751. ,$selected = ""
  3752. ,$pi_name=""
  3753. ,$disabled=""
  3754. ,$type=""
  3755. ,$size=1
  3756. )
  3757. // +---------------------------------------------------------------------------+
  3758. // | 機能 オプションリスト作成(配列より)
  3759. // | 書式 DATABOX_getoptionlistary($selectionary,"afield[".$fid."]",$fvalue,$pi_name, $disabled,$type);
  3760. // +---------------------------------------------------------------------------+
  3761. // | 引数 $ary:
  3762. // | 引数 $fld:
  3763. // | 引数 $selected:選択値 省略時
  3764. // | 引数 $pi_name: 'databox' 'userbox' 'formbox'
  3765. // | 引数 $disabled:defalt=""
  3766. // | 引数 $type:defalt="" 14=multiselect
  3767. // +---------------------------------------------------------------------------+
  3768. // | 戻値 nomal:オプションリスト |
  3769. // +---------------------------------------------------------------------------+
  3770. {
  3771. if ($pi_name==""){
  3772. $lang_box="LANG_DATABOX";
  3773. }else{
  3774. $lang_box="LANG_".strtoupper($pi_name);
  3775. }
  3776. global $$lang_box;
  3777. $lang_box=$$lang_box;
  3778. if ($type==14 OR $type==18){
  3779. //$selectedary=array[];
  3780. $selectedary=explode(":",$selected);
  3781. }
  3782. if ($size=="" OR $size==0){
  3783. $size=1;
  3784. }
  3785. $retval = '';
  3786. $retval .= "<select ";
  3787. if ($type==14 OR $type==18){
  3788. $retval .= ' name="'.$fld.'[]" ';
  3789. $retval .= ' multiple="multiple" ';
  3790. $retval .= ' size="'.$size.'"';
  3791. }else{
  3792. $retval .= ' name="'.$fld.'"';
  3793. }
  3794. $retval .= $disabled.">".LB;
  3795. if ($type==7 ){
  3796. if ($ary[0]==""){
  3797. }else{
  3798. $retval .= "<option value=''>{$lang_box['selectit']}</option>".LB;
  3799. }
  3800. }
  3801. foreach($ary as $k => $v) {
  3802. $retval .= "<option value=\"".$k."\"";
  3803. //echo "k=".$k."sa=".$selectedary."s=".$selected."<br>";
  3804. if ($selected==""){
  3805. }else{
  3806. if ($type==14 OR $type==18){
  3807. if( in_array($k,$selectedary) ){//@@@@@
  3808. $retval .= " selected=\"selected\" ";
  3809. }
  3810. }else{
  3811. if( $k == $selected ){//@@@@@
  3812. $retval .= " selected=\"selected\" ";
  3813. }
  3814. }
  3815. }
  3816. $retval .= ">";
  3817. $retval .= $v;
  3818. $retval .= "</option>".LB;
  3819. }
  3820. $retval .= '</select>';
  3821. return $retval;
  3822. }
  3823. function DATABOX_getoptionlist(
  3824. $kind
  3825. ,$selected = 0
  3826. ,$relno=0
  3827. ,$pi_name=""
  3828. ,$disabled=""
  3829. ,$selectit=true
  3830. ,$selectlist=""
  3831. ,$fname=""
  3832. )
  3833. // +---------------------------------------------------------------------------+
  3834. // | 機能 オプションリスト作成
  3835. // | 書式 DATABOX_getoptionlist($kind)
  3836. // | DATABOX_getoptionlist("fieldset",$fieldset_id,0,$pi_name,"",0 );
  3837. // | DATABOX_getoptionlist("group",$categorygroup_id,0,$pi_name,"",0 );
  3838. // +---------------------------------------------------------------------------+
  3839. // | 引数 $kind:項目種類
  3840. // | 引数 $selected:選択値
  3841. // | 引数 $relno
  3842. // | 引数 $pi_name: 'databox' 'userbox' 'formbox'
  3843. // | 引数 $disabled
  3844. // | 引数 $selectit
  3845. // | 引数 $selectlist 既定リストの時既定リスト名
  3846. // | 引数 $fname フィールド名
  3847. // +---------------------------------------------------------------------------+
  3848. // | 戻値 nomal:オプションリスト |
  3849. // +---------------------------------------------------------------------------+
  3850. //update 20101122,20110613,20120525,20140724
  3851. {
  3852. global $_CONF;
  3853. global $_TABLES;
  3854. global $LANG_configselects;
  3855. if ($pi_name==""){
  3856. $lang_box="LANG_DATABOX";
  3857. }else{
  3858. $lang_box="LANG_".strtoupper($pi_name);
  3859. }
  3860. global $$lang_box;
  3861. $lang_box=$$lang_box;
  3862. if ($fname==""){
  3863. $fname=$kind;
  3864. }
  3865. $retval = '';
  3866. $retval .= "<select name='$fname' $disabled>".LB;
  3867. if ($selectit==="all"){
  3868. $retval .= "<option value=\"all\">{$lang_box['selectall']}</option>".LB;
  3869. }elseif ($selectit){
  3870. $retval .= "<option value=0>{$lang_box['selectit']}</option>".LB;
  3871. }
  3872. if ($kind=="layout"){
  3873. $retval .= "<option value=0>{$lang_box['byconfig']}</option>".LB;
  3874. $ary=$LANG_configselects[strtolower($pi_name)][22];
  3875. foreach($ary as $k => $v) {
  3876. $retval .= "<option value=\"".$v."\"";
  3877. if( $v == $selected ){//@@@@@
  3878. $retval .= " selected=\"selected\" ";
  3879. }
  3880. $retval .= ">";
  3881. $retval .= $k;
  3882. $retval .= "</option>".LB;
  3883. next($ary);
  3884. }
  3885. }else if ($kind=="language_id"){
  3886. $retval .= "<option value=0> </option>".LB;
  3887. $ary=$_CONF['languages'];
  3888. foreach($ary as $k => $v) {
  3889. $retval .= "<option value=\"".$k."\"";
  3890. if( $k == $selected ){//@@@@@
  3891. $retval .= " selected=\"selected\" ";
  3892. }
  3893. $retval .= ">";
  3894. $retval .= $v;
  3895. $retval .= "</option>".LB;
  3896. next($ary);
  3897. }
  3898. }else{
  3899. if ($kind=="group"){
  3900. $where="";
  3901. $table=$_TABLES[strtoupper($pi_name).'_def_group'];
  3902. $fields= 'group_id,name,orderno';
  3903. }else if ($kind=="parent"){
  3904. $where="";
  3905. $table=$_TABLES[strtoupper($pi_name).'_def_category'];
  3906. $fields= 'category_id,name,orderno';
  3907. }else if ($kind=="fieldset"){
  3908. $where="";
  3909. $table=$_TABLES[strtoupper($pi_name).'_def_fieldset'];
  3910. $fields= 'fieldset_id,name,fieldset_id';
  3911. }else if ($kind=="selectlist"){
  3912. $where="";
  3913. $table=$_TABLES[strtoupper($pi_name).'_mst'];
  3914. $fields= 'DISTINCT kind,kind,kind';
  3915. }else if ($kind=="selectlist_mst"){
  3916. $table=$_TABLES[strtoupper($pi_name).'_mst'];
  3917. $where="kind='{$selectlist}'";
  3918. if ($relno<>0) $where.=" AND relno='{$relno}'";
  3919. $fields= 'no,value,orderno';
  3920. }else if ($kind=="fieldgroupno"){
  3921. $where="kind='fieldgroup'";
  3922. $table=$_TABLES[strtoupper($pi_name).'_mst'];
  3923. $fields= 'DISTINCT no,value,no';
  3924. }else if ($kind=="csvsel"){
  3925. $where="";
  3926. $table=$_TABLES[strtoupper($pi_name).'_def_csv_sel'];
  3927. $fields= 'csv_sel_id,name,csv_sel_id*-1';
  3928. }else{
  3929. $table=$_TABLES[strtoupper($pi_name).'_mst'];
  3930. $where="kind='{$kind}'";
  3931. if ($relno<>0) $where.=" AND relno='{$relno}'";
  3932. $fields= 'no,value,orderno';
  3933. }
  3934. $retval .= COM_optionList (
  3935. $table
  3936. , $fields
  3937. , $selected,2,$where);
  3938. }
  3939. $retval .= '</select>';
  3940. if ($disabled==="disabled"){
  3941. $retval .= " <input type='hidden' name='{$fname}' value='{$selected}'>";
  3942. }
  3943. return $retval;
  3944. }
  3945. function DATABOX_dltbldt(
  3946. $filenm
  3947. ,$fld
  3948. ,$tbl
  3949. ,$where=""
  3950. ,$order=""
  3951. ,$pi_name=""
  3952. ,$addition=false
  3953. )
  3954. // +---------------------------------------------------------------------------+
  3955. // | 機能 テーブルのデータをCSV形式でダウンロードする
  3956. // | 書式 DATABOX_dltbldt($filenm,$fld,$tbl,$where,$order,$type,$pi_name,false);
  3957. // +---------------------------------------------------------------------------+
  3958. // | 引数 $filenm :
  3959. // | 引数 $fld :
  3960. // | 引数 $tbl :
  3961. // | 引数 $where :
  3962. // | 引数 $order :
  3963. // | 引数 $pi_name:plugin name 'databox' 'userbox' 'formbox'
  3964. // | 引数 $addition:false=追加項目なし、 true=追加項目あり
  3965. // +---------------------------------------------------------------------------+
  3966. // | 戻値 nomal:
  3967. // +---------------------------------------------------------------------------+
  3968. //20100910
  3969. //@@@@@ 追加予定 カテゴリも
  3970. {
  3971. global $_CONF;
  3972. $dm=",";//区切り文字
  3973. $ec="`";//フィールド囲み文字
  3974. if ($addition){
  3975. $addition_def=DATABOX_getadditiondef($pi_name);
  3976. }
  3977. $retval="";
  3978. //file output open
  3979. $curdatetime = date("Y_m_d_H_i_s");
  3980. //$outfile = tempnam($_CONF['path_data'] ."tmp", $filenm);
  3981. $outfile = $_CONF['path_data'] . $filenm."_".$curdatetime;
  3982. $file = @fopen( $outfile, 'w' );
  3983. if ( $file === false ) {
  3984. $retval .= "ERR! ".$outfile ." is not writable!<br ".XHTML.">" . LB;
  3985. return $retval;
  3986. }
  3987. //-----
  3988. $sql = "SELECT DISTINCT ";
  3989. foreach($fld as $k => $v) {
  3990. $sql .=$k.",";
  3991. }
  3992. $sql=rtrim($sql,",");
  3993. $sql.= " FROM ".$tbl;
  3994. if (!empty($where)) {
  3995. $sql.=" WHERE ".$where;
  3996. }
  3997. if (!empty($order)) {
  3998. $sql.=" ORDER BY ".$order;
  3999. }
  4000. //-----
  4001. $result = DB_query ($sql);
  4002. //-----1行目ヘッダ
  4003. $w='';
  4004. foreach($fld as $k => $v) {
  4005. $w .=$ec.$k.$ec.$dm;
  4006. }
  4007. //addition field
  4008. if ($addition){
  4009. if ($addition_def<>""){
  4010. $s=$addition_def;
  4011. foreach($s as $k1 =>$v1){
  4012. $w .=$ec.$s[$k1]['templatesetvar'].$ec.$dm;
  4013. }
  4014. }
  4015. }
  4016. $w=rtrim($w,$dm);
  4017. $w = str_replace( array( '<?', '?>' ), array( '(@', '@)' ),$w );
  4018. fputs( $file, $w.LB);
  4019. //-----2行目ヘッダ
  4020. $w="";
  4021. foreach($fld as $k => $v) {
  4022. $w .=$ec.$v['name'].$ec.$dm;
  4023. }
  4024. //addition field
  4025. if ($addition){
  4026. if ($addition_def<>""){
  4027. $s=$addition_def;
  4028. foreach($s as $k1 =>$v1){
  4029. $w .=$ec.$addition_def[$k1]['name'].$ec.$dm;
  4030. }
  4031. }
  4032. }
  4033. $w=rtrim($w,$dm);
  4034. $w = str_replace( array( '<?', '?>' ), array( '(@', '@)' ),$w );
  4035. fputs( $file, $w.LB);
  4036. //-----3行目以降
  4037. while( $A = DB_fetchArray( $result ) ) {
  4038. $w="";
  4039. foreach($fld as $k => $v) {
  4040. $w .=$ec.$A[$k].$ec.$dm;
  4041. }
  4042. //
  4043. if ($addition){
  4044. $wkary=DATABOX_getaddtionfields($A["id"],$addition_def,$pi_name);
  4045. $s=$addition_def;
  4046. foreach($s as $k1 =>$v1){
  4047. //echo "k1=".$k1."<br ".XHTML.">";
  4048. if (isset($wkary[$k1])) {
  4049. //echo "wkary=".$wkary[$k1]."<br>";
  4050. $w .=$ec.$wkary[$k1].$ec.$dm;
  4051. }else{
  4052. //echo "DD<br>";
  4053. $w .=$ec.$ec.$dm;
  4054. }
  4055. }
  4056. }
  4057. $w=rtrim($w,$dm);
  4058. $w = str_replace( array( '<?', '?>' ), array( '(@', '@)' ),$w );
  4059. fputs( $file, $w.LB);
  4060. }
  4061. fclose($file);
  4062. $filename=basename($outfile).".csv";
  4063. $dir=dirname($outfile);
  4064. header ("Content-Disposition: attachment; filename=$filename");
  4065. header ("Content-type: application/x-csv");
  4066. readfile ($outfile);
  4067. flush();
  4068. $rt=unlink($outfile);
  4069. return "";
  4070. }
  4071. function DATABOX_getfeaturedimage(
  4072. $id
  4073. ,$pi_name
  4074. ,$mode="imgsrc"
  4075. )
  4076. // +---------------------------------------------------------------------------+
  4077. // | 機能 featuredimage取得
  4078. // | 書式 DATABOX_getfeaturedimage($id,$pi_name)
  4079. // | typw14(外画像)表示する先頭(順番が若い)追加項目をfeaturedimageとして取得
  4080. // +---------------------------------------------------------------------------+
  4081. // | 引数 $id:
  4082. // | 引数 $pi_name:plugin name 'databox' 'userbox' 'formbox'
  4083. // +---------------------------------------------------------------------------+
  4084. // | 戻値 nomal:featuredimage
  4085. // +---------------------------------------------------------------------------+
  4086. {
  4087. global $_CONF;
  4088. global $_TABLES;
  4089. $box_conf="_".strtoupper($pi_name)."_CONF";
  4090. global $$box_conf;
  4091. $box_conf=$$box_conf;
  4092. $tbl1=$_TABLES[strtoupper($pi_name).'_addition'];
  4093. $tbl2=$_TABLES[strtoupper($pi_name).'_def_field'];
  4094. $rt="";
  4095. $sql = "SELECT t1.value";
  4096. $sql .= " FROM ";
  4097. $sql .= " {$tbl1} AS t1";
  4098. $sql .= " ,{$tbl2} AS t2";
  4099. $sql .= " WHERE t1.id=".$id;
  4100. $sql .= " AND t1.field_id =t2.field_id";
  4101. $sql .= " AND t2.type=12";
  4102. $sql .= " AND allow_display=0";
  4103. $sql .= " ORDER BY orderno";
  4104. $result = DB_query ($sql);
  4105. $numrows = DB_numRows ($result);
  4106. if ($numrows > 0) {
  4107. $A = DB_fetchArray ($result);
  4108. $value=$A['value'];
  4109. if ($value<>""){
  4110. $url=$_CONF['site_url'] ."/".$box_conf['imgfile_frd'] ;
  4111. $url.= $value ;
  4112. if ($mode=="imgsrc"){
  4113. $rt='<img src="'.$url.'" />';
  4114. }else{
  4115. $rt=$url;
  4116. }
  4117. }
  4118. }
  4119. return $rt;
  4120. }
  4121. function DATABOX_getheadercode(
  4122. $kind
  4123. ,$template
  4124. ,$pi_name
  4125. ,$id
  4126. ,$title
  4127. ,$meta_description
  4128. ,$meta_keywords
  4129. ,$description
  4130. ,$additionfields=""
  4131. ,$addition_def=""
  4132. ,$chk_user=""
  4133. ,$fieldset_id=""
  4134. ,$fieldset_name=""
  4135. )
  4136. // +---------------------------------------------------------------------------+
  4137. // | 機能 HEADERCODE 編集
  4138. // | 書式 DATABOX_getheadercode("data",$template,$pi_name,$A['id'],$A['title']
  4139. // | ,$A['meta_description'],$A['meta_keyword'],$A['description']);
  4140. // +---------------------------------------------------------------------------+
  4141. // | 引数 $kind "data","category"
  4142. // | 引数 $template
  4143. // | 引数 $pi_name
  4144. // | 引数 $id
  4145. // | 引数 $title
  4146. // | 引数 $meta_description
  4147. // | 引数 $meta_keywords
  4148. // | 引数 $description
  4149. // +---------------------------------------------------------------------------+
  4150. // | 戻値 nomal:HEADERCODE
  4151. // +---------------------------------------------------------------------------+
  4152. {
  4153. global $_CONF;
  4154. global $_TABLES;
  4155. global $_IMAGE_TYPE;
  4156. $box_conf="_".strtoupper($pi_name)."_CONF";
  4157. global $$box_conf;
  4158. $box_conf=$$box_conf;
  4159. $retval="";
  4160. $currenturl= COM_getCurrentURL();
  4161. $site_logo= $_CONF['layout_url'] . '/images/logo.' . $_IMAGE_TYPE ;
  4162. $og_type="article";
  4163. $og_title=$title;
  4164. if ($box_conf['meta_tags'] > 0) {
  4165. $retval .= COM_createMetaTags($meta_description, $meta_keywords);
  4166. }
  4167. if ($_CONF['meta_tags']==0 OR $meta_description=="") {
  4168. $og_description = $description;
  4169. }else{
  4170. $og_description = $meta_description;
  4171. }
  4172. $og_description= COM_getTextContent(PLG_replaceTags($og_description));
  4173. if ($kind==="data"){
  4174. $og_image =DATABOX_getfeaturedimage($id,$pi_name,"url");
  4175. if ($og_image===""){
  4176. $og_image=$site_logo;
  4177. }
  4178. }else{
  4179. $og_image =$box_conf["default_img_url"];
  4180. if ($og_image===""){
  4181. $og_image=$site_logo;
  4182. }
  4183. }
  4184. //テンプレートフォルダの設定
  4185. $tmplfld=DATABOX_templatePath($kind,$template,$pi_name);
  4186. if (file_exists ($tmplfld."/headercode.thtml")) {
  4187. $tpl = new Template($tmplfld);
  4188. $tpl->set_file (array (
  4189. 'tpl' => 'headercode.thtml',
  4190. ));
  4191. $tpl->set_var('xhtml', XHTML);
  4192. $tpl->set_var('site_url', $_CONF['site_url']);
  4193. $tpl->set_var('site_admin_url', $_CONF['site_admin_url']);
  4194. $tpl->set_var('layout_url', $_CONF['layout_url']);
  4195. $tpl->set_var ('currenturl', htmlspecialchars($currenturl, ENT_QUOTES, 'UTF-8'));
  4196. $tpl->set_var ('site_name', $_CONF['site_name']);
  4197. $tpl->set_var ('site_mail', $_CONF['site_mail']);
  4198. $tpl->set_var ('og_title', $og_title);
  4199. $tpl->set_var ('og_image', $og_image);
  4200. $tpl->set_var ('og_description', $og_description);
  4201. $tpl->set_var ('og_type', $og_type);
  4202. $tpl->set_var ('fieldset_name', $fieldset_name);
  4203. //facebook
  4204. $facebook_consumer_key = trim($_CONF['facebook_consumer_key']);
  4205. $tpl->set_var ('facebook_consumer_key', $facebook_consumer_key);
  4206. if ($kind==="data"){
  4207. DATABOX_getaddtionfieldsDisp($additionfields,$addition_def,$tpl,$chk_user,$pi_name,$fieldset_id);
  4208. }
  4209. $tpl->parse ('output', 'tpl');
  4210. $retval .= $tpl->finish ($tpl->get_var ('output'));
  4211. }
  4212. return $retval;
  4213. }
  4214. function DATABOX_getfields(
  4215. $pi_name
  4216. , $fieldset_id
  4217. )
  4218. {
  4219. global $_TABLES;
  4220. if ($fieldset_id==0){
  4221. $table=$_TABLES[strtoupper($pi_name).'_def_field'];
  4222. }else{
  4223. $table=$_TABLES[strtoupper($pi_name).'_def_fieldset_assignments'];
  4224. }
  4225. $fields = array();
  4226. // Get a list of additionfields in the selected field
  4227. $sql = "SELECT DISTINCT field_id ";
  4228. $sql .= " FROM {$table}";
  4229. if ($fieldset_id<>0){
  4230. $sql .= " WHERE ";
  4231. $sql .= " fieldset_id = $fieldset_id";
  4232. }
  4233. $result = DB_query ($sql);
  4234. $num = DB_numRows ($result);
  4235. if ($num<>0){
  4236. while ($A = DB_fetchArray($result)) {
  4237. $fields[] = $A['field_id'];
  4238. }
  4239. }
  4240. return $fields;
  4241. }
  4242. function DATABOX_getAry(
  4243. $kind
  4244. ,$relno=0
  4245. ,$selectlist
  4246. ,$pi_name=""
  4247. )
  4248. {
  4249. global $_TABLES;
  4250. // if ($kind=="selectlist_mst"){
  4251. $table=$_TABLES[strtoupper($pi_name).'_mst'];
  4252. $where=" WHERE kind='{$selectlist}'";
  4253. if ($relno<>0) $where.=" AND relno='{$relno}'";
  4254. $fields= 'no,value';
  4255. $order=" ORDER BY orderno";
  4256. // }
  4257. $ary=array();
  4258. $sql = "SELECT ";
  4259. $sql .= $fields ;
  4260. $sql .= " FROM " ;
  4261. $sql .= $table ;
  4262. $sql .= $where ;
  4263. $sql .= $order ;
  4264. $result = DB_query($sql);
  4265. $nrows = DB_numRows($result);
  4266. for( $i=0; $i < $nrows; $i++) {
  4267. $A = DB_fetchArray($result, true);
  4268. $ary[$A[0]] = $A[1];
  4269. }
  4270. return $ary;
  4271. }
  4272. function DATABOX_categorycount(
  4273. $pi_name
  4274. ,$categorygroup_id
  4275. ,$categorygroup_code
  4276. ,$permission=""
  4277. ,$numberformat=''
  4278. )
  4279. // +---------------------------------------------------------------------------+
  4280. // | 機能 カテゴリ件数表示
  4281. // +---------------------------------------------------------------------------+
  4282. // | 書式 databox_categorycount()
  4283. // | 書式 databox_categorycount(1)
  4284. // | 書式 databox_count("","japan")
  4285. // +---------------------------------------------------------------------------+
  4286. // | 引数 $pi_name:plugin名
  4287. // | 引数 $group_id:カテゴリグループid
  4288. // | 引数 $group_code:カテゴリグループコード
  4289. // | カテゴリグループid もカテゴリグループコードも指定ない場合は
  4290. // | 親カテゴリグループなしのカテゴリの件数
  4291. // | 引数 $permission :ブランク または ignore
  4292. // | 引数 $numberformat :yes
  4293. // +---------------------------------------------------------------------------+
  4294. // | 戻値 nomal:カテゴリ件数
  4295. // | (アクセス権のあるデータが登録されていないカテゴリの件数は含みません)
  4296. // +---------------------------------------------------------------------------+
  4297. {
  4298. global $_TABLES;
  4299. //-----
  4300. $tbl3=$_TABLES[strtoupper($pi_name).'_def_category'] ;
  4301. $tbl1=$_TABLES[strtoupper($pi_name).'_category'] ;
  4302. $tbl4=$_TABLES[strtoupper($pi_name).'_def_group'] ;
  4303. $tbl2=$_TABLES[strtoupper($pi_name).'_base'] ;
  4304. if ($categorygroup_id =="" AND $categorygroup_code=="") {
  4305. $categorygroup_id=0;
  4306. }else{
  4307. if ($categorygroup_id==""){
  4308. $categorygroup_id=DATABOX_codetoid( $categorygroup_code,strtoupper($pi_name).'_def_group',"group_id");
  4309. if ($categorygroup_id==0){
  4310. return 0;
  4311. }
  4312. }
  4313. }
  4314. //-----
  4315. $sql = "SELECT ".LB;
  4316. $sql .= " t1.category_id".LB;
  4317. //$sql .= " ,Count(t1.id) AS count".LB;
  4318. $sql .= " FROM ".LB;
  4319. $sql .= " {$tbl1} AS t1 ".LB;
  4320. $sql .= " ,{$tbl2} AS t2 ".LB;
  4321. $sql .= " ,{$tbl3} AS t3 ".LB;
  4322. $sql .= " ,{$tbl4} AS t4 ".LB;
  4323. $sql .= " WHERE ".LB;
  4324. $sql .= " t1.id = t2.id ".LB;
  4325. $sql .= " AND t1.category_id = t3.category_id ".LB;
  4326. $sql .= " AND t3.categorygroup_id = ".$categorygroup_id.LB;
  4327. $sql .= " AND t3.categorygroup_id = t4.group_id ".LB;
  4328. //管理者の時,下書データも含む
  4329. //if ( SEC_hasRights('databox.admin')) {
  4330. //}else{
  4331. $sql .= " AND t2.draft_flag=0".LB;
  4332. //}
  4333. //アクセス権のないデータ はのぞく
  4334. if (strtoupper($permission)=="IGNORE"){
  4335. }else{
  4336. $sql .= COM_getPermSql('AND',0,2,"t2").LB;
  4337. }
  4338. //公開日以前のデータはのぞく
  4339. $sql .= " AND (released <= NOW())".LB;
  4340. //公開終了日を過ぎたデータはのぞく
  4341. $sql .= " AND (expired=0 OR expired > NOW())".LB;
  4342. $sql .= " GROUP BY ".LB;
  4343. $sql .= " t1.category_id".LB;
  4344. $result = DB_query ($sql);
  4345. $cnt = DB_numRows ($result);
  4346. if (strtoupper($numberformat)=="YES"){
  4347. $rt=COM_NumberFormat($cnt);
  4348. }else{
  4349. $rt=$cnt;
  4350. }
  4351. return $rt;
  4352. }
  4353. function DATABOX_Confirmation(
  4354. $pi_name
  4355. ,$mode
  4356. )
  4357. // +---------------------------------------------------------------------------+
  4358. // | 機能 確認画面
  4359. // | 書式 DATABOX_Confirmation($pi_name,$mode)
  4360. // fnc_Confirmation proversion
  4361. // +---------------------------------------------------------------------------+
  4362. // | 引数 $pi_name:plugin名
  4363. // | 引数 $mode:カテゴリグループid
  4364. // +---------------------------------------------------------------------------+
  4365. // | 戻値 nomal:
  4366. // +---------------------------------------------------------------------------+
  4367. {
  4368. global $_CONF;
  4369. global $LANG_ADMIN;
  4370. $lang_box_admin="LANG_".strtoupper($pi_name)."_ADMIN";
  4371. global $$lang_box_admin;
  4372. $lang_box_admin=$$lang_box_admin;
  4373. $tmpl = new Template ($_CONF['path'] . "plugins/".THIS_PLUGIN."/templates/admin/");
  4374. $tmpl->set_file(array('confirm' => 'confirmation.thtml'));
  4375. $tmpl->set_var('site_admin_url', $_CONF['site_admin_url']);
  4376. $tmpl->set_var('gltoken_name', CSRF_TOKEN);
  4377. $tmpl->set_var('gltoken', SEC_createToken());
  4378. $tmpl->set_var ( 'xhtml', XHTML );
  4379. //
  4380. $actionname=$lang_box_admin[$mode];
  4381. $actionprg="{$_CONF['site_admin_url']}/plugins/".THIS_SCRIPT."?mode={$mode}exec";
  4382. $tmpl->set_var('actionname', $actionname);
  4383. $tmpl->set_var('actionprg', $actionprg);
  4384. $tmpl->set_var('help', $lang_box_admin[$mode.'msg']);
  4385. $btn_value=$LANG_ADMIN['submit'];
  4386. $confirm_value=$lang_box_admin['confirm'];
  4387. $btn2="";
  4388. $btn3="";
  4389. if ($mode==="datadelete"){
  4390. $tmpl->set_var('lang_checklist', $lang_box_admin['fieldset'].":");
  4391. $checklist=DATABOX_getcheckList ("fieldset","",$pi_name);
  4392. $tmpl->set_var('checklist', $checklist);
  4393. $btn_value=$lang_box_admin['delete1'];
  4394. $confirm_value=$lang_box_admin['delete1']." ".$lang_box_admin['confirm'];
  4395. $confirm_value2=$lang_box_admin['delete2']." ".$lang_box_admin['confirm'];
  4396. $confirm_value3=$lang_box_admin['delete3']." ".$lang_box_admin['confirm'];
  4397. $btn2="<input type='submit' name='action' value='{$lang_box_admin['delete2']}'"
  4398. ." onclick=\"return confirm('{$confirm_value2}');\"".xhtml.">".LB;
  4399. $btn3="<input type='submit' name='action' value='{$lang_box_admin['delete3']}'"
  4400. ." onclick=\"return confirm('{$confirm_value3}');\"".xhtml.">".LB;
  4401. }
  4402. // SAVE、CANCEL ボタン
  4403. $tmpl->set_var('lang_confirm', $confirm_value);
  4404. $tmpl->set_var('lang_submit', $btn_value);
  4405. $tmpl->set_var('btn2', $btn2);
  4406. $tmpl->set_var('btn3', $btn3);
  4407. $tmpl->set_var('lang_cancel', $LANG_ADMIN['cancel']);
  4408. $tmpl->set_var('mode', $mode."exec");
  4409. $tmpl->parse ('output', 'confirm');
  4410. $comfirm = $tmpl->finish ($tmpl->get_var ('output'));
  4411. $retval = $comfirm;
  4412. return $retval;
  4413. }
  4414. //==============================================================================
  4415. //lib_datetimeedit.php →
  4416. function DATABOX_datetimeedit(
  4417. $datetime_value
  4418. ,$lang
  4419. ,$datetime_name="datetime"
  4420. ,$mode="datetime"
  4421. ) {
  4422. global $_CONF;
  4423. $var = $lang;
  4424. global $$var;
  4425. $lang_ary=$$var;
  4426. if ($datetime_value==""){
  4427. $datetime_year = date('Y');
  4428. $datetime_month = date('m');
  4429. $datetime_day = date('d');
  4430. //
  4431. $datetime_hour = date ('H');
  4432. $datetime_minute = date ('i') ;
  4433. }else{
  4434. $datetime_year = date('Y', $datetime_value);
  4435. $datetime_month = date('m', $datetime_value);
  4436. $datetime_day = date('d', $datetime_value);
  4437. //
  4438. $datetime_hour = date ('H', $datetime_value);
  4439. $datetime_minute = date ('i', $datetime_value) ;
  4440. }
  4441. $rt="";
  4442. //Year
  4443. $year_options = COM_getYearFormOptions ($datetime_year);
  4444. $rt.="<select name=\"".$datetime_name."_year\">".LB;
  4445. $rt.=$year_options.LB;
  4446. $rt.="</select>".$lang_ary['yy'].LB;
  4447. //month
  4448. $month_options = COM_getMonthFormOptions ($datetime_month);
  4449. $rt.="<select name=\"".$datetime_name."_month\">".LB;
  4450. $rt.=$month_options.LB;
  4451. $rt.="</select>".$lang_ary['mm'].LB;
  4452. //day
  4453. $day_options = COM_getDayFormOptions ($datetime_day);
  4454. $rt.="<select name=\"".$datetime_name."_day\">".LB;
  4455. $rt.=$day_options.LB;
  4456. $rt.="</select>".$lang_ary['dd'].LB;
  4457. //hour
  4458. if ($mode==="datetime"){
  4459. if ($_CONF['hour_mode'] == 24) {
  4460. $hour_options = COM_getHourFormOptions ($datetime_hour, 24);
  4461. }else{
  4462. $datetime_hour_wk=$datetime_hour;
  4463. if ($datetime_hour_wk >= 12) {
  4464. if ($datetime_hour_wk > 12) {
  4465. $datetime_hour_wk = $datetime_hour_wk - 12;
  4466. }
  4467. $ampm = 'pm';
  4468. } else {
  4469. $ampm = 'am';
  4470. }
  4471. $ampm_select = COM_getAmPmFormSelection ($datetime_name.'_ampm', $ampm);
  4472. if (empty ($ampm_select)) {
  4473. $ampm_select = '<input type="hidden" name="cmt_close_ampm" value=""' . XHTML . '>';
  4474. }
  4475. $rt.=$ampm_select;
  4476. $hour_options = COM_getHourFormOptions ($datetime_hour_wk);
  4477. }
  4478. $rt.="<select name=\"".$datetime_name."_hour\">".LB;
  4479. $rt.=$hour_options.LB;
  4480. $rt.="</select>:".LB;
  4481. //minute
  4482. $minute_options = COM_getMinuteFormOptions ($datetime_minute);
  4483. $rt.="<select name=\"".$datetime_name."_minute\">".LB;
  4484. $rt.=$minute_options.LB;
  4485. $rt.="</select>".LB;
  4486. }
  4487. return $rt;
  4488. }
  4489. function DATABOX_datetimeedit_R(
  4490. $datetime_ary
  4491. ,$lang
  4492. ,$datetime_name="datetime"
  4493. ) {
  4494. global $_CONF;
  4495. $var = $lang;
  4496. global $$var;
  4497. $lang_ary=$$var;
  4498. if (!is_array($datetime_ary)){
  4499. return "";
  4500. }
  4501. $rt="";
  4502. //Year
  4503. $year_options = COM_getYearFormOptions ($datetime_ary['year']);
  4504. $rt.="<select name=\"".$datetime_name."_year\">".LB;
  4505. $rt.=$year_options.LB;
  4506. $rt.="</select>".$lang_ary['yy'].LB;
  4507. //month
  4508. $month_options = COM_getMonthFormOptions ($datetime_ary['month']);
  4509. $rt.="<select name=\"".$datetime_name."_month\">".LB;
  4510. $rt.=$month_options.LB;
  4511. $rt.="</select>".$lang_ary['mm'].LB;
  4512. //day
  4513. $day_options = COM_getDayFormOptions ($datetime_ary['day']);
  4514. $rt.="<select name=\"".$datetime_name."_day\">".LB;
  4515. $rt.=$day_options.LB;
  4516. $rt.="</select>".$lang_ary['dd'].LB;
  4517. //hour
  4518. if ($datetime_ary['hour']<>""){
  4519. if ($_CONF['hour_mode'] == 24) {
  4520. $hour_options = COM_getHourFormOptions ($datetime_ary['hour'], 24);
  4521. }else{
  4522. $ampm_select = COM_getAmPmFormSelection ($datetime_name.'_ampm', $datetime_ary['ampm']);
  4523. if (empty ($ampm_select)) {
  4524. $ampm_select = '<input type="hidden" name="cmt_close_ampm" value=""' . XHTML . '>';
  4525. }
  4526. $rt.=$ampm_select;
  4527. $hour_options = COM_getHourFormOptions ($datetime_ary['hour']);
  4528. }
  4529. $rt.="<select name=\"".$datetime_name."_hour\">".LB;
  4530. $rt.=$hour_options.LB;
  4531. $rt.="</select>:".LB;
  4532. //minute
  4533. $minute_options = COM_getMinuteFormOptions ($datetime_ary['minute']);
  4534. $rt.="<select name=\"".$datetime_name."_minute\">".LB;
  4535. $rt.=$minute_options.LB;
  4536. $rt.="</select>".LB;
  4537. }
  4538. return $rt;
  4539. }
  4540. //==============================================================================
  4541. //lib_outlog.php →
  4542. //log 出力モード設定 0:作成しない,1:ファイルに出力 2:画面にも出力
  4543. //$logmode =2;
  4544. //$logfile = $_CONF['path_log'] . "profile_point.log";
  4545. //echo OutLog( "----- photomailcheck.php start",$logmode);
  4546. // ログ出力処理
  4547. function DATABOX_OutLog( $logentry ,$logfile,$logmode=1)
  4548. {
  4549. global $_CONF,$LANG01;
  4550. $retval = '';
  4551. if (!empty($logmode)) {
  4552. if( !empty( $logentry )) {
  4553. $logentry = str_replace( array( '<?', '?>' ), array( '(@', '@)' ),
  4554. $logentry );
  4555. $timestamp = strftime( '%c' );
  4556. if (!file_exists($logfile)) {
  4557. echo $logfile ." doesn't exist. ";
  4558. exit();
  4559. }
  4560. if (!is_writable($logfile)) {
  4561. echo $logfile ." cannot be written. ";
  4562. exit();
  4563. }
  4564. $file = fopen( $logfile, 'a' );
  4565. if( empty($file)) {
  4566. $retval .= $LANG01[33] . ' ' . $logfile . ' (' . $timestamp . ')<br/><br/>' . LB;
  4567. } else {
  4568. fputs( $file, "$timestamp - $logentry\n" );
  4569. }
  4570. if ($logmode ==2){
  4571. $retval .="$timestamp - $logentry<br/>" . LB;
  4572. }
  4573. }
  4574. }
  4575. return $retval;
  4576. }
  4577. //==============================================================================
  4578. //lib_getfilelist.php →
  4579. // 指定フォルダのファイルの一覧を取得
  4580. function DATABOX_getfilelist(
  4581. $fd
  4582. ,$exte =""
  4583. )
  4584. {
  4585. $fary= array();
  4586. $dir=opendir($fd);
  4587. while(($ent = readdir()) !==FALSE){
  4588. if ($exte=="") {
  4589. $fary[$i] = $ent;
  4590. $i++;
  4591. }else{
  4592. $w=explode('.',$ent);
  4593. if (strtolower($w[1])===$exte){
  4594. $fary[$i] = $ent;
  4595. $i++;
  4596. }
  4597. }
  4598. }
  4599. return $fary;
  4600. }
  4601. function DATABOX_getDateTimeFormat( $date,$format )
  4602. {
  4603. if( empty( $date )) {
  4604. $stamp = time();
  4605. } else if( is_numeric( $date )){
  4606. $stamp = $date;
  4607. }else{
  4608. $stamp = strtotime( $date );
  4609. }
  4610. $date = strftime( $format, $stamp );
  4611. return array( $date, $stamp );
  4612. }
  4613. function DATABOX_getTimeFormat( $value )
  4614. {
  4615. $rt="";
  4616. if ($value==""){
  4617. $rt="";
  4618. }else{
  4619. if ($_CONF['hour_mode']=='24'){
  4620. $rt=date('H:i', $value );
  4621. }else{
  4622. $rt=date('h:i', $value );
  4623. if (date('H',$value)>=12){
  4624. $rt.=" PM";
  4625. }else{
  4626. $rt.=" AM";
  4627. }
  4628. }
  4629. }
  4630. return $rt;
  4631. }
  4632. function DATABOX_fieldvalue(
  4633. $pi_name
  4634. ,$id
  4635. ,$code
  4636. ,$field_id
  4637. ,$field_code
  4638. ,$option = ""
  4639. )
  4640. // +---------------------------------------------------------------------------+
  4641. // | 機能 追加項目表示用取得
  4642. // | 書式 DATABOX_fieldvalue($pi_name,$id,$code,$field_id,$field_code,$option)
  4643. // +---------------------------------------------------------------------------+
  4644. // | 引数 $pi_name:plugin name 'databox' 'userbox' 'formbox'
  4645. // | 引数 $id:
  4646. // | 引数 $code:
  4647. // | 引数 $field_id:
  4648. // | 引数 $field_code:
  4649. // | 引数 $option:'','name','description','yes','value2','disp','no'
  4650. // +---------------------------------------------------------------------------+
  4651. // | 戻値 nomal:追加項目表示用
  4652. // +---------------------------------------------------------------------------+
  4653. {
  4654. global $_TABLES;
  4655. global $_CONF;
  4656. global $_PLUGINS;
  4657. $lang_noyes="LANG_".strtoupper($pi_name)."_NOYES";
  4658. global $$lang_noyes;
  4659. $lang_noyes=$$lang_noyes;
  4660. $lang_box="LANG_".strtoupper($pi_name);
  4661. global $$lang_box;
  4662. $lang_box=$$lang_box;
  4663. $separater=$lang_box['field_separater'];
  4664. $table_base=$_TABLES[strtoupper($pi_name).'_base'];
  4665. $table_def_field=$_TABLES[strtoupper($pi_name).'_def_field'];
  4666. $table_addition=$_TABLES[strtoupper($pi_name).'_addition'];
  4667. $table_def_fieldset_assignments
  4668. =$_TABLES[strtoupper($pi_name).'_def_fieldset_assignments'];
  4669. //-----引数チェック
  4670. if (is_null($id)){
  4671. if (is_null($code) OR $code===""){
  4672. $id=0;
  4673. }else{
  4674. if ($pi_name=="userbox"){
  4675. $id=DATABOX_codetoid($code,'users',"uid","username");
  4676. }else{
  4677. $id=DATABOX_codetoid($code,strtoupper($pi_name).'_base');
  4678. }
  4679. }
  4680. }
  4681. if ($id===0) {
  4682. return "";
  4683. }
  4684. if (is_null($field_id)){
  4685. if (is_null($field_code) OR $field_code===""){
  4686. $field_id=0;
  4687. }else{
  4688. $field_id=DATABOX_codetoid($field_code,strtoupper($pi_name).'_def_field'
  4689. ,"field_id","templatesetvar");
  4690. }
  4691. }
  4692. if ($field_id===0) {
  4693. return "";
  4694. }
  4695. $fieldset_id=DB_getItem( $table_base,"fieldset_id","id=".$id );
  4696. if ($fieldset_id==0){
  4697. }else{
  4698. $w=DB_getItem( $table_def_fieldset_assignments
  4699. ,"fieldset_id","fieldset_id=$fieldset_id AND field_id=".$field_id );
  4700. if ($w==""){
  4701. return "";
  4702. }
  4703. }
  4704. //
  4705. $sql = "SELECT DISTINCT ".LB;
  4706. $sql .= " t.value ".LB;
  4707. $sql .= " ,m.type ".LB;
  4708. $sql .= " ,m.name ".LB;
  4709. $sql .= " ,m.description ".LB;
  4710. $sql .= " ,m.selection ".LB;
  4711. $sql .= " ,m.selectlist ".LB;
  4712. $sql .= " ,m.dfid ".LB;
  4713. $sql .= " FROM ".LB;
  4714. $sql .= "{$table_addition} AS t".LB;
  4715. $sql .= " , {$table_def_field} AS m".LB;
  4716. $sql .= " WHERE ".LB;
  4717. $sql .= " t.id = {$id} AND t.field_id = {$field_id} ".LB;
  4718. $sql .= " AND m.field_id = {$field_id} ".LB;
  4719. $sql .= " AND m.allow_display = 0 ".LB;
  4720. $result = DB_query ($sql);
  4721. $num = DB_numRows ($result);
  4722. $rt="";
  4723. if ($num<>0){
  4724. $A = DB_fetchArray ($result);
  4725. $A = array_map('stripslashes', $A);
  4726. if ($option=="name"){
  4727. $rt=$A['name'];
  4728. }else if ($option=="description"){
  4729. $rt=$A['description'];
  4730. }else if ($option=="datatitle"){
  4731. if (in_array('databox', $_PLUGINS)) {
  4732. $rt=COM_applyFilter(DB_getItem( $_TABLES['DATABOX_base'] ,"title","code='{$A['value']}'"));
  4733. }
  4734. }else if ($option=="datadescription"){
  4735. if (in_array('databox', $_PLUGINS)) {
  4736. $rt=COM_applyFilter(DB_getItem( $_TABLES['DATABOX_base'] ,"description","code='{$A['value']}'"));
  4737. }
  4738. }else{
  4739. $selectionary=DATABOX_getselectionary($A['selection']);
  4740. $selectlist=$A['selectlist'];
  4741. $type=$A['type'];
  4742. $value=$A['value'];
  4743. $dfid= $A['dfid'];
  4744. $format = DB_getItem($_TABLES['dateformats'], "format", "dfid = $dfid");
  4745. if( empty( $format )) {
  4746. $format = $_CONF['date'];
  4747. }
  4748. switch ($type) {
  4749. case 12://画像(外記憶)
  4750. case 13://添付ファイル
  4751. if ($value===""){
  4752. }else{
  4753. list($readfile,$rt)=explode("|",$value);
  4754. }
  4755. break;
  4756. case 11://画像(DB記憶)
  4757. if ($value===""){
  4758. }else{
  4759. $rt="<img src=\"data:image/jpg;base64,";
  4760. $rt .="{$value}\"".XHTML.">";
  4761. }
  4762. break;
  4763. case 2://いいえ/はい
  4764. if ($option=="yes"){
  4765. if ($value==1){
  4766. $rt=1;
  4767. }
  4768. }else{
  4769. $rt= $lang_noyes[$value];
  4770. }
  4771. break;
  4772. case 7://オプションリスト(選択肢)
  4773. case 8://ラジオボタンリスト(選択肢)
  4774. $rt= $selectionary[$value];
  4775. break;
  4776. case 14://マルチセレクトリスト(選択肢)
  4777. $wkary=explode(":",$value);
  4778. $wk="";
  4779. for( $x = 0; $x < sizeof( $wkary ); $x++ ) {
  4780. $wk.=$selectionary[$wkary[$x]].$separater;
  4781. }
  4782. $rt= rtrim($wk,$separater);
  4783. break;
  4784. case 10:// 複数行テキストフィールド(HTML NG)
  4785. $w=DATABOX_nl2br($value);
  4786. $w=DATABOX_autolink($w);
  4787. $rt= $w;
  4788. break;
  4789. case 9://オプションリスト(マスター)
  4790. case 16: //ラジオボタン(マスター)
  4791. $mstitems=DATABOX_getMstItems($selectlist,$value,$pi_name);
  4792. $rt= $mstitems['value'];
  4793. if ($option=="value2"){
  4794. $rt= $mstitems['value2'];
  4795. }else if ($option=="disp"){
  4796. $rt= $mstitems['disp'];
  4797. }else if ($option=="no"){
  4798. $rt= $mstitems['no'];
  4799. }else{
  4800. $rt= $mstitems['value'];
  4801. }
  4802. break;
  4803. case 18://マルチセレクトリスト(マスター)
  4804. $wkary=explode(":",$value);
  4805. $wk="";
  4806. $wk_value2="";
  4807. $wk_disp="";
  4808. $wk_no="";
  4809. for( $x = 0; $x < sizeof( $wkary ); $x++ ) {
  4810. $mstitems=DATABOX_getMstItems($selectlist,$wkary[$x],$pi_name);
  4811. $wk.=$mstitems['value'].$separater;
  4812. $wk_value2.=$mstitems['value2'].$separater;
  4813. $wk_disp.=$mstitems['disp'].$separater;
  4814. $wk_no.=$mstitems['no'].$separater;
  4815. }
  4816. if ($option=="value2"){
  4817. $rt= rtrim($wk_value2,$separater);
  4818. }else if ($option=="disp"){
  4819. $rt= rtrim($wk_disp,$separater);
  4820. }else if ($option=="no"){
  4821. $rt= rtrim($wk_no,$separater);
  4822. }else{
  4823. $rt= rtrim($wk,$separater);
  4824. }
  4825. break;
  4826. case 4://日時
  4827. if ($value<>""){
  4828. $w=DATABOX_getDateTimeFormat($value,$format);
  4829. $rt= $w[0];
  4830. }
  4831. break;
  4832. case 3://日付
  4833. if ($value<>""){
  4834. $rt=strftime( $_CONF['shortdate'], $value );
  4835. }
  4836. break;
  4837. case 21://money 通貨;
  4838. $dc = $_CONF['decimal_count'];
  4839. $ts = $_CONF['thousand_separator'];
  4840. $ds = $_CONF['decimal_separator'];
  4841. $rt= number_format( (float)$value, $dc, $ds, $ts );
  4842. break;
  4843. case 5://メールアドレス
  4844. case 6://url';
  4845. case 0:// 一行テキストフィールド
  4846. case 1:// 複数行テキストフィールド(HTML OK)
  4847. case 20:// 複数行テキストフィールド(HTML OK TinyMCE)
  4848. case 19:// 複数行テキストフィールド(HTML OK CKEditor)
  4849. default:
  4850. $rt= $value;
  4851. }
  4852. }
  4853. }
  4854. return $rt;
  4855. }
  4856. function DATABOX_fieldownload(
  4857. $pi_name
  4858. ,$id
  4859. ,$code
  4860. ,$field_id
  4861. ,$field_code
  4862. ,$mode
  4863. )
  4864. // +---------------------------------------------------------------------------+
  4865. // | 機能 ファイルダウンロード
  4866. // | 書式 DATABOX_fieldownload($pi_name,$id,$code,$field_id,$field_code)
  4867. // +---------------------------------------------------------------------------+
  4868. // | 引数 $pi_name:plugin name 'databox' 'userbox' 'formbox'
  4869. // | 引数 $id:
  4870. // | 引数 $code:
  4871. // | 引数 $field_id:
  4872. // | 引数 $field_code:
  4873. // | 引数 $mode ナシ、display
  4874. // +---------------------------------------------------------------------------+
  4875. // | 戻値 nomal:
  4876. // +---------------------------------------------------------------------------+
  4877. {
  4878. global $_TABLES;
  4879. global $_CONF;
  4880. $box_conf="_".strtoupper($pi_name)."_CONF";
  4881. global $$box_conf;
  4882. $box_conf=$$box_conf;
  4883. $lang_box="LANG_".strtoupper($pi_name);
  4884. global $$lang_box;
  4885. $lang_box=$$lang_box;
  4886. $separater=$lang_box['field_separater'];
  4887. $table_base=$_TABLES[strtoupper($pi_name).'_base'];
  4888. $table_def_field=$_TABLES[strtoupper($pi_name).'_def_field'];
  4889. $table_addition=$_TABLES[strtoupper($pi_name).'_addition'];
  4890. $table_def_fieldset_assignments
  4891. =$_TABLES[strtoupper($pi_name).'_def_fieldset_assignments'];
  4892. //-----引数チェック
  4893. if (is_null($id) OR $id===""){
  4894. if (is_null($code) OR $code===""){
  4895. $id=0;
  4896. }else{
  4897. if ($pi_name=="userbox"){
  4898. $id=DATABOX_codetoid($code,'users',"uid","username");
  4899. }else{
  4900. $id=DATABOX_codetoid($code,strtoupper($pi_name).'_base');
  4901. }
  4902. }
  4903. }
  4904. if ($id===0) {
  4905. return "download argument error id";
  4906. }
  4907. if (is_null($field_id) OR $field_id===""){
  4908. if (is_null($field_code) OR $field_code===""){
  4909. $field_id=0;
  4910. }else{
  4911. $field_id=DATABOX_codetoid($field_code,strtoupper($pi_name).'_def_field'
  4912. ,"field_id","templatesetvar");
  4913. }
  4914. }
  4915. if ($field_id===0) {
  4916. return "download Argument error field_id";
  4917. }
  4918. $fieldset_id=DB_getItem( $table_base,"fieldset_id","id=".$id );
  4919. if ($fieldset_id==0){
  4920. }else{
  4921. $w=DB_getItem( $table_def_fieldset_assignments
  4922. ,"fieldset_id","fieldset_id=$fieldset_id AND field_id=".$field_id );
  4923. if ($w==""){
  4924. return "download drgument error id field_id";
  4925. }
  4926. }
  4927. //
  4928. $sql = "SELECT DISTINCT ".LB;
  4929. $sql .= " t.value ".LB;
  4930. $sql .= " ,m.allow_display ".LB;
  4931. $sql .= " ,d.group_id ".LB;
  4932. $sql .= " ,d.owner_id ".LB;
  4933. $sql .= " FROM ".LB;
  4934. $sql .= "{$table_addition} AS t".LB;
  4935. $sql .= " , {$table_def_field} AS m".LB;
  4936. $sql .= " , {$table_base} AS d".LB;
  4937. $sql .= " WHERE ".LB;
  4938. $sql .= " t.id = {$id} AND t.field_id = {$field_id} ".LB;
  4939. $sql .= " AND m.field_id = {$field_id} ".LB;
  4940. $sql .= " AND m.type = 13 ".LB;
  4941. $sql .= " AND d.id = {$id} ".LB;
  4942. //下書データはのぞく
  4943. $sql .= " AND d.draft_flag=0".LB;
  4944. //公開日以前のデータはのぞく
  4945. $sql .= " AND (released <= NOW())";
  4946. //公開終了日を過ぎたデータはのぞく
  4947. $sql .= " AND (expired=0 OR expired > NOW())";
  4948. //アクセス権のないデータ はのぞく
  4949. $sql .= COM_getPermSql('AND');
  4950. $result = DB_query ($sql);
  4951. $num = DB_numRows ($result);
  4952. $rt="Target file is not found";
  4953. if ($num<>0){
  4954. $A = DB_fetchArray ($result);
  4955. $A = array_map('stripslashes', $A);
  4956. $value=$A['value'];
  4957. $group_id = $A['group_id'];
  4958. $owner_id = $A['owner_id'];
  4959. $allow_display= $A['allow_display'];
  4960. $chk_user=DATABOX_chkuser($group_id,$owner_id,$pi_name.".admin");
  4961. if ($value<>""){
  4962. $chk=false;
  4963. //表示する
  4964. if ($allow_display==='0') {
  4965. $chk=true;
  4966. //ログインユーザのみ
  4967. }else if ($allow_display==='1'){
  4968. if ($chk_user>=1000) {
  4969. $chk=true;
  4970. }
  4971. //グループとadmin権のある人のみ表示
  4972. }else if ($allow_display==='2'){
  4973. if ($chk_user>=1010) {
  4974. $chk=true;
  4975. }
  4976. //所有者とadmin権のある人のみ
  4977. }else if ($allow_display==='3'){
  4978. if ($chk_user>=1011) {
  4979. $chk=true;
  4980. }
  4981. //admin権のある人のみ
  4982. }else if ($allow_display==='4'){
  4983. if ($chk_user>=1100) {
  4984. $chk=true;
  4985. }
  4986. }
  4987. if ($chk) {
  4988. list($readfile,$filename)=explode("|",$value);
  4989. list($dummy,$extention)=explode(".",$filename);
  4990. $filetype=DATABOX_getFileTypeAry($extention );
  4991. if ($filetype<>""){
  4992. $path=$box_conf['file_path'];
  4993. if (file_exists($path.$readfile)){
  4994. if ($mode=="display"){
  4995. if ($extention=="pdf"){
  4996. header('Content-Type: '.$filetype);
  4997. header('Content-Disposition: inline; filename="'.$filename.'"');
  4998. readfile($path.$readfile);
  4999. //download log
  5000. //download count
  5001. exit;
  5002. }
  5003. }else{
  5004. header('Content-Type: '.$filetype);
  5005. header('Content-Disposition: attachment; filename="'.$filename.'"');
  5006. readfile($path.$readfile);
  5007. //download log
  5008. //download count
  5009. exit;
  5010. }
  5011. }
  5012. }
  5013. }
  5014. }
  5015. }
  5016. return $rt;
  5017. }
  5018. function DATABOX_getFileTypeAry(
  5019. $extension
  5020. )
  5021. {
  5022. $ary=array();
  5023. $ary['odt']="application/vnd.oasis.opendocument.text";//open office writer*
  5024. $ary['doc']="application/msword";//Microsoft Word
  5025. $ary['docx']="application/vnd.openxmlformats";// Microsoft Office Word 2007*
  5026. $ary['html']="text/html";
  5027. $ary['odb']="application/octet-stream ";//OpenOffice Base*
  5028. $ary['odf']="application/vnd.oasis.opendocument.formula";//OpenOffice Calc*
  5029. $ary['odg']="application/vnd.oasis.opendocument.graphics";//OpenOffice Draw*
  5030. $ary['odm']="application/vnd.oasis.opendocument.text-master";// OpenOffice Writer*
  5031. $ary['odp']="application/vnd.oasis.opendocument.presentation";//OpenOffice Impress*
  5032. $ary['ods']="application/vnd.oasis.opendocument.spreadsheet";//OpenOffice Calc*
  5033. $ary['otg']="application/vnd.oasis.opendocument.graphics-template";//OpenOffice Draw*
  5034. $ary['oth']="application/octet-stream";// OpenOffice.org Writer*
  5035. $ary['otp']="application/vnd.oasis.opendocument.presentation-template";//OpenOffice Impress*
  5036. $ary['ots']="application/octet-stream";//OtsAV*
  5037. $ary['ott']="application/vnd.oasis.opendocument.formula-template ";//OpenOffice Writer*
  5038. $ary['oxt']="application/vnd.openofficeorg.extension";//OpenOffice *
  5039. $ary['pdf']="application/pdf";
  5040. $ary['ppt']="application/mspowerpoint";//Microsoft PowerPoint*
  5041. $ary['pptx']="application/vnd.openxmlformats";//Microsoft Office PowerPoint 2007*
  5042. $ary['txt']="text/plain";
  5043. $ary['xls']="application/vnd.ms-excel";//Microsoft Excel*
  5044. $ary['xlsx']="application/vnd.openxmlformats ";//Microsoft Office Excel 2007*
  5045. $ary['xml']="text/xml";
  5046. if ($extention===""){
  5047. $rt= $ary;
  5048. }else{
  5049. $rt= $ary[$extension];
  5050. }
  5051. return $rt;
  5052. }
  5053. // +---------------------------------------------------------------------------+
  5054. // | 機能 指定追加項目の指定データに一致する件数表示
  5055. // +---------------------------------------------------------------------------+
  5056. // | 書式 DATABOX_count_each_afield("class","1")
  5057. // +---------------------------------------------------------------------------+
  5058. // | 引数 $pi_name:plugin name 'databox' 'userbox' 'formbox'
  5059. // | 引数 $templatesetvar:追加項目のテーマ変数
  5060. // | 引数 $value:指定データ値
  5061. // | 引数 $type_id:タイプID
  5062. // | 引数 $permission :ブランク または ignore
  5063. // | 引数 $numberformat :ブランク または yes
  5064. // +---------------------------------------------------------------------------+
  5065. // | 戻値 nomal:指定追加項目の指定データに一致する件数
  5066. // +---------------------------------------------------------------------------+
  5067. function DATABOX_count_each_afield(
  5068. $pi_name="databox"
  5069. ,$templatesetvar=""
  5070. ,$value=""
  5071. ,$type_id=0
  5072. ,$permission=''
  5073. ,$numberformat=''
  5074. )
  5075. {
  5076. global $_TABLES;
  5077. if ($templatesetvar=="" OR $value=="" ){
  5078. return "";
  5079. }
  5080. if ($type_id=="" OR $type_id==NULL){
  5081. $type_id=0;
  5082. }
  5083. //-----
  5084. $tbl1=$_TABLES[strtoupper($pi_name).'_base'] ;
  5085. $tbl2=$_TABLES[strtoupper($pi_name).'_addition'] ;
  5086. $tbl3=$_TABLES[strtoupper($pi_name).'_def_field'];
  5087. //-----
  5088. $sql = "SELECT ".LB;
  5089. $sql .= " t1.id".LB;
  5090. $sql .= " FROM ".LB;
  5091. $sql .= " {$tbl1} AS t1 ".LB;
  5092. $sql .= " ,{$tbl2} AS t2 ".LB;
  5093. $sql .= " ,{$tbl3} AS t3 ".LB;
  5094. $sql .= " WHERE ".LB;
  5095. //@@@@@@@@@@@------>
  5096. //下書はのぞく
  5097. $sql .= " t1.draft_flag=0".LB;
  5098. //アクセス権のないデータ はのぞく
  5099. if (strtoupper($permission)=="IGNORE"){
  5100. }else{
  5101. $sql .= COM_getPermSql('AND').LB;
  5102. }
  5103. //公開日以前のデータはのぞく
  5104. $sql .= " AND (released <= NOW())".LB;
  5105. //公開終了日を過ぎたデータはのぞく
  5106. $sql .= " AND (expired=0 OR expired > NOW())".LB;
  5107. //@@@@@@@@@@@<------
  5108. $sql .= " AND fieldset_id = ".$type_id.LB;
  5109. $sql .= " AND t1.id = t2.id ".LB;
  5110. $sql .= " AND t2.field_id= t3.field_id" .LB;
  5111. $sql .= " AND t3.templatesetvar='". $templatesetvar ."'".LB;
  5112. $sql .= " AND t2.value='". $value ."'".LB;
  5113. $result = DB_query ($sql);
  5114. $cnt = DB_numRows ($result);
  5115. if (strtoupper($numberformat)=="YES"){
  5116. $rt=COM_NumberFormat($cnt);
  5117. }else{
  5118. $rt=$cnt;
  5119. }
  5120. return $rt;
  5121. }
  5122. function DATABOX_math(
  5123. $pi_name= 'databox'
  5124. ,$method= 'count'
  5125. ,$templatesetvar=""
  5126. ,$type_id=""
  5127. ,$category_id=null
  5128. ,$category_code=null
  5129. ,$mode=''
  5130. ,$roundprecision=''
  5131. ,$numberformat=''
  5132. ,$permission=""
  5133. )
  5134. // +---------------------------------------------------------------------------+
  5135. // | 機能 指定アトリビュートの指定値(count average max min sum)を取得する
  5136. // | 複数カテゴリ条件選択が可能(OR と AND)
  5137. // +---------------------------------------------------------------------------+
  5138. // | 書式 DATABOX_math("databox","count","1")
  5139. // +---------------------------------------------------------------------------+
  5140. // | 引数 $pi_name:plugin name 'databox' 'userbox' 'formbox'
  5141. // | 引数 $method:count average avg max min sum
  5142. // | 引数 $templatesetvar:追加項目のテーマ変数
  5143. // | 引数 $value:指定データ値
  5144. // | 引数 $type_id:タイプID
  5145. // | 引数 $category_id:カテゴリid
  5146. // | 引数 $category_code :
  5147. // | 引数 $mode :ブランク または AND
  5148. // | 引数 $roundprecision:〜-3,-2,-1,0,1,2,3
  5149. // | 引数 $numberformat :yes
  5150. // +---------------------------------------------------------------------------+
  5151. // | 戻値 nomal:指定値
  5152. // +---------------------------------------------------------------------------+
  5153. {
  5154. global $_TABLES;
  5155. global $_CONF;
  5156. if ($templatesetvar=="" ){
  5157. return "";
  5158. }
  5159. if ($type_id=="" OR $type_id==NULL){
  5160. $type_id=0;
  5161. }
  5162. $method=strtoupper($method);
  5163. if ($method=="MAX" OR $method=="MIN" OR $method=="SUM" OR $method=="AVG" OR $method=="COUNT" ){
  5164. }else if ($method=="AVERAGE" ){
  5165. $method="AVG";
  5166. }else{
  5167. $method="COUNT";
  5168. }
  5169. //-----category check
  5170. $ids="";
  5171. $idsary=array();
  5172. if (is_null($category_id) OR $category_id==0){
  5173. if (is_null($category_code)){
  5174. }else{
  5175. $w=explode("|",$category_code);
  5176. foreach( $w as $val ){
  5177. if ($ids<>""){
  5178. $ids.=",";
  5179. }
  5180. $w_id=DATABOX_codetoid($val,strtoupper($pi_name).'_def_category',"category_id");
  5181. $idsary[]=$w_id;
  5182. $ids.=$w_id;
  5183. }
  5184. }
  5185. }else{
  5186. $ids=$category_id;
  5187. $idsary[]=$category_id;
  5188. }
  5189. //-----
  5190. $tbl1=$_TABLES[strtoupper($pi_name).'_base'] ;
  5191. $tbl2=$_TABLES[strtoupper($pi_name).'_addition'] ;
  5192. $tbl3=$_TABLES[strtoupper($pi_name).'_def_field'];
  5193. $tbl4=$_TABLES[strtoupper($pi_name).'_category'] ;
  5194. $tbl5=$_TABLES[strtoupper($pi_name).'_def_category'] ;
  5195. $type=DB_getItem( $tbl3 ,"type","templatesetvar='{$templatesetvar}'");
  5196. //-----
  5197. $sql = "SELECT ".LB;
  5198. if ($type==15 OR $type==21 OR strtoupper($numberformat)=="YES") {
  5199. $sql .= $method ."(t2.value + 0) AS rt".LB;
  5200. }else{
  5201. $sql .= $method ."(t2.value) AS rt".LB;
  5202. }
  5203. $sql .= " FROM ".LB;
  5204. $sql .= " {$tbl1} AS t1 ".LB;
  5205. $sql .= " ,{$tbl2} AS t2 ".LB;
  5206. $sql .= " ,{$tbl3} AS t3 ".LB;
  5207. $sql .= " WHERE ".LB;
  5208. //@@@@@@@@@@@------>
  5209. //下書はのぞく
  5210. $sql .= " t1.draft_flag=0".LB;
  5211. //アクセス権のないデータ はのぞく
  5212. if (strtoupper($permission)=="IGNORE"){
  5213. }else{
  5214. $sql .= COM_getPermSql('AND').LB;
  5215. }
  5216. //公開日以前のデータはのぞく
  5217. $sql .= " AND (released <= NOW())".LB;
  5218. //公開終了日を過ぎたデータはのぞく
  5219. $sql .= " AND (expired=0 OR expired > NOW())".LB;
  5220. //@@@@@@@@@@@<------
  5221. $sql .= " AND fieldset_id=".$type_id;
  5222. $sql .= " AND t1.id = t2.id ".LB;
  5223. $sql .= " AND t2.field_id= t3.field_id" .LB;
  5224. $sql .= " AND t3.templatesetvar='". $templatesetvar ."'".LB;
  5225. if (count($idsary)<>0){
  5226. if (strtoupper($mode)=="AND"){
  5227. $w="";
  5228. foreach( $idsary as $val ){
  5229. if ($w<>""){
  5230. $w.=" AND ";
  5231. }
  5232. $w.=$val." IN (SELECT t4.category_id";
  5233. $w.=" FROM {$tbl4} AS t4 ,{$tbl5} AS t5";
  5234. $w.=" WHERE t1.id = t4.id AND t4.category_id = t5.category_id AND t5.allow_display<2)";
  5235. }
  5236. }else{
  5237. $w= "t1.id IN (SELECT id FROM {$tbl4} AS t4 ,{$tbl5} AS t5 ";
  5238. $w.="WHERE t4.category_id = t5.category_id AND t5.allow_display<2 AND t4.category_id IN ({$ids})) ";
  5239. }
  5240. $sql.=" AND ({$w})".LB;
  5241. }
  5242. $result = DB_query ($sql);
  5243. $numrows = DB_numRows ($result);
  5244. if ($numrows > 0) {
  5245. $A = DB_fetchArray ($result);
  5246. $A = array_map('stripslashes', $A);
  5247. $rt=$A['rt'];;
  5248. }else{
  5249. if ($method=="COUNT"){
  5250. $rt=0;
  5251. }else{
  5252. $rt="";
  5253. }
  5254. }
  5255. if ( is_numeric($rt) ) {
  5256. if (!is_numeric($roundprecision)){
  5257. $roundprecision=0;
  5258. }
  5259. $rt=round($rt,$roundprecision);
  5260. if (strtoupper($numberformat)=="YES"){
  5261. $rt=number_format( $rt,
  5262. $roundprecision, $_CONF['decimal_separator'], $_CONF['thousand_separator'] );
  5263. }
  5264. }
  5265. return $rt;
  5266. }
  5267. function DATABOX_getcheckboxary(
  5268. $ary
  5269. ,$fld
  5270. ,$selected = ""
  5271. ,$pi_name=""
  5272. ,$disabled=""
  5273. ,$type=""
  5274. ,$size=1
  5275. )
  5276. // +---------------------------------------------------------------------------+
  5277. // | 機能 チェックボックス作成(配列より)
  5278. // | 書式 DATABOX_getcheckboxary($selectionary,"afield[".$fid."]",$fvalue,$pi_name, $disabled,$type);
  5279. // +---------------------------------------------------------------------------+
  5280. // | 引数 $ary:
  5281. // | 引数 $fld:
  5282. // | 引数 $selected:選択値 省略時
  5283. // | 引数 $pi_name: 'databox' 'userbox' 'formbox'
  5284. // | 引数 $disabled:defalt=""
  5285. // | 引数 $type:defalt="" 14=multiselect
  5286. // +---------------------------------------------------------------------------+
  5287. // | 戻値 nomal:オプションリスト |
  5288. // +---------------------------------------------------------------------------+
  5289. {
  5290. if ($pi_name==""){
  5291. $lang_box="LANG_DATABOX";
  5292. }else{
  5293. $lang_box="LANG_".strtoupper($pi_name);
  5294. }
  5295. global $$lang_box;
  5296. $lang_box=$$lang_box;
  5297. $selectedary=explode(":",$selected);
  5298. $retval = '';
  5299. foreach($ary as $k => $v) {
  5300. $retval .= '<span style="white-space:nowrap">';
  5301. $retval .= '<input type="checkbox" name="' . $fld . '[]" value="' . $k ;
  5302. $retval .= '"';
  5303. if ($selected==""){
  5304. }else{
  5305. if( in_array($k,$selectedary) ){//@@@@@
  5306. $retval .= ' checked="checked"';
  5307. }
  5308. }
  5309. $retval .= '>' . stripslashes( $v ) . '</span>' . LB;
  5310. }
  5311. return $retval;
  5312. }
  5313. function DATABOX_isExcepted(
  5314. $code
  5315. ,$excepts)
  5316. {
  5317. foreach ($excepts as $except) {
  5318. if (strlen($except) > 0) {
  5319. if (preg_match('/' . $except . '/' , $code)) {
  5320. return TRUE;
  5321. }
  5322. }
  5323. }
  5324. return FALSE;
  5325. }
  5326. ?>