Index: branches/comu-ver2/data/class/pages/admin/design/LC_Page_Admin_Design.php
===================================================================
--- branches/comu-ver2/data/class/pages/admin/design/LC_Page_Admin_Design.php	(revision 18189)
+++ branches/comu-ver2/data/class/pages/admin/design/LC_Page_Admin_Design.php	(revision 18190)
@@ -79,12 +79,15 @@
 
         // ブロック配置用データを取得
-        $sel   = ", pos.target_id, pos.bloc_id, pos.bloc_row ";
+        $sel   = ", pos.target_id, pos.bloc_id, pos.bloc_row ,pos.anywhere";
         $from  = ", dtb_blocposition AS pos";
         $where = " where ";
-        $where .= " lay.page_id = ? AND ";
-        $where .= "lay.page_id = pos.page_id AND exists (select bloc_id from dtb_bloc as blc where pos.bloc_id = blc.bloc_id) ORDER BY lay.page_id,pos.target_id, pos.bloc_row, pos.bloc_id ";
+        $where .= "( pos.anywhere = 1 OR (lay.page_id = ? AND ";
+        $where .= "lay.page_id = pos.page_id AND exists (select bloc_id from dtb_bloc as blc where pos.bloc_id = blc.bloc_id) )) ORDER BY lay.page_id,pos.target_id, pos.bloc_row, pos.bloc_id ";
+//        $where .= "((lay.page_id = ? AND ";
+//        $where .= "lay.page_id = pos.page_id AND exists (select bloc_id from dtb_bloc as blc where pos.bloc_id = blc.bloc_id) )) ORDER BY lay.page_id,pos.target_id, pos.bloc_row, pos.bloc_id ";
+        
         $arrData = array($page_id);
         $arrBlocPos = $this->lfgetLayoutData($sel, $from, $where, $arrData );
-
+                
         // データの存在チェックを行う
         $arrPageData = $objLayout->lfgetPageData("page_id = ?", array($page_id));
@@ -143,5 +146,7 @@
                 $arrUpdBlocData[$upd_cnt]['target_id']  = $arrTargetFlip[$_POST['target_id_'.$upd_cnt]];    // ターゲットID
                 $arrUpdBlocData[$upd_cnt]['top']        = $_POST['top_'.$upd_cnt];                          // TOP座標
+                $arrUpdBlocData[$upd_cnt]['anywhere']        = $_POST['anywhere_'.$upd_cnt];                     //全ページ適用か
                 $arrUpdBlocData[$upd_cnt]['update_url'] = $_SERVER['HTTP_REFERER'];                         // 更新URL
+                
             }
 
@@ -178,6 +183,7 @@
                 $ins_sql .= "   ,? ";           // ブロックの並び順序
                 $ins_sql .= "   ,(SELECT filename FROM dtb_bloc WHERE bloc_id = ?) ";           // ファイル名称
+                $ins_sql .= "   ,? ";           // 全ページフラグ
                 $ins_sql .= "   )  ";
-
+                
                 // insertデータ生成
                 $arrInsData = array($page_id,
@@ -185,6 +191,21 @@
                                     $arrUpdBlocData[$key]['id'],
                                     $arrUpdBlocData[$key]['bloc_row'],
-                                    $arrUpdBlocData[$key]['id']
+                                    $arrUpdBlocData[$key]['id'],
+                                    $arrUpdBlocData[$key]['anywhere']
                                     );
+                $count = $objDBConn->getOne("SELECT COUNT(*) FROM dtb_blocposition WHERE anywhere = 1 AND bloc_id = ?",array($arrUpdBlocData[$key]['id']));
+                                    
+               if($arrUpdBlocData[$key]['anywhere'] == 1){
+                   $count = $objDBConn->getOne("SELECT COUNT(*) FROM dtb_blocposition WHERE anywhere = 1 AND bloc_id = ?",array($arrUpdBlocData[$key]['id']));
+                   $objDBConn->getLastQuery();
+                   if($count != 0){
+                       continue;
+                   }else{
+                   }
+               }else{
+                   if($count > 0){
+                       $objDBConn->query("DELETE FROM dtb_blocposition WHERE anywhere = 1 AND bloc_id = ?",array($arrUpdBlocData[$key]['id']));
+                   }
+               }
                 // SQL実行
                 $arrRet = $objDBConn->query($ins_sql,$arrInsData);
@@ -228,13 +249,16 @@
                 $tpl_arrBloc = $this->lfSetBlocData($arrBloc, $val, $tpl_arrBloc, $cnt);
                 $cnt++;
-            }
-        }
-
+            }else{
+            }
+        }
+        
+                
         // 未使用のブロックデータを追加
         foreach($arrBloc as $key => $val){
             if (!$this->lfChkBloc($val, $tpl_arrBloc)) {
-                $val['target_id'] = 5;  // 未使用に追加する
+                $val['target_id'] = 7;  // 未使用に追加する
                 $tpl_arrBloc = $this->lfSetBlocData($arrBloc, $val, $tpl_arrBloc, $cnt);
                 $cnt++;
+            }else{
             }
         }
@@ -374,5 +398,8 @@
         $tpl_arrBloc[$cnt]['bloc_row'] =
             isset($val['bloc_row']) ? $val['bloc_row'] : "";
-
+        $tpl_arrBloc[$cnt]['anywhere'] = $val['anywhere'];
+        if($val['anywhere'] == 1){
+            $tpl_arrBloc[$cnt]['anywhere_selected'] = 'checked="checked"';
+        }
         foreach($arrBloc as $bloc_key => $bloc_val){
             if ($bloc_val['bloc_id'] == $val['bloc_id']) {
@@ -382,5 +409,5 @@
         }
         $tpl_arrBloc[$cnt]['name'] = $bloc_name;
-
+                
         return $tpl_arrBloc;
     }
@@ -400,5 +427,5 @@
             }
         }
-
+        
         // 配列に存在しなければFlaseを返す
         return false;
@@ -437,5 +464,5 @@
         $arrUpdData = array();          // 更新データ生成用
         $filename = $arrPageData[0]['filename'];
-
+        
         $arrPreData = $objLayout->lfgetPageData(" page_id = ? " , array("0"));
 
@@ -480,4 +507,5 @@
         $sql .= "     ,tpl_dir = ?";
         $sql .= "     ,filename = ?";
+        $sql .= "     ,anywhere = ?";
         $sql .= " where page_id = 0";
 
@@ -488,4 +516,5 @@
                             ,USER_DIR . "templates/" . TEMPLATE_NAME . "/"
                             ,$filename
+                           
                             );
 
