Index: branches/beta/data/class/SC_UploadFile.php
===================================================================
--- branches/beta/data/class/SC_UploadFile.php	(revision 293)
+++ branches/beta/data/class/SC_UploadFile.php	(revision 14676)
@@ -7,307 +7,402 @@
 
 $SC_UPLOADFILE_DIR = realpath(dirname( __FILE__));
-require_once($SC_UPLOADFILE_DIR . "/../lib/gdthumb.php");	
+require_once($SC_UPLOADFILE_DIR . "/../lib/gdthumb.php");
+require_once($SC_UPLOADFILE_DIR . "/../include/ftp.php");
 
 /* ¥¢¥Ã¥×¥í¡¼¥É¥Õ¥¡¥¤¥ë´ÉÍý¥¯¥é¥¹ */
 class SC_UploadFile {
-	var $temp_dir;
-	var $save_dir;
-	var $keyname;	// ¥Õ¥¡¥¤¥ëinput¥¿¥°¤Îname
-	var $width;		// ²£¥µ¥¤¥º
-	var $height;	// ½Ä¥µ¥¤¥º
-	var $arrExt;	// »ØÄê¤¹¤ë³ÈÄ¥»Ò
-	var $temp_file;	// ÊÝÂ¸¤µ¤ì¤¿¥Õ¥¡¥¤¥ëÌ¾
-	var $save_file; // DB¤«¤éÆÉ¤ß½Ð¤·¤¿¥Õ¥¡¥¤¥ëÌ¾
-	var $disp_name;	// ¹àÌÜÌ¾
-	var $size;		// À©¸Â¥µ¥¤¥º
-	var $necessary; // É¬¿Ü¤Î¾ì¹ç:true
-	var $image;		// ²èÁü¤Î¾ì¹ç:true
-	
-	// ¥Õ¥¡¥¤¥ë´ÉÍý¥¯¥é¥¹
-	function SC_UploadFile($temp_dir, $save_dir) {
-		$this->temp_dir = $temp_dir;
-		$this->save_dir = $save_dir;
-		$this->file_max = 0;
-	}
-
-	// ¥Õ¥¡¥¤¥ë¾ðÊóÄÉ²Ã
-	function addFile($disp_name, $keyname, $arrExt, $size, $necessary=false, $width=0, $height=0, $image=true) {
-		$this->disp_name[] = $disp_name;
-		$this->keyname[] = $keyname;
-		$this->width[] = $width;
-		$this->height[] = $height;
-		$this->arrExt[] = $arrExt;
-		$this->size[] = $size;
-		$this->necessary[] = $necessary;
-		$this->image[] = $image;
-	}
-	// ¥µ¥à¥Í¥¤¥ë²èÁü¤ÎºîÀ®
-	function makeThumb($src_file, $width, $height) {
-		// °ì°Õ¤ÊID¤ò¼èÆÀ¤¹¤ë¡£
-		$uniqname = date("mdHi") . "_" . uniqid("");
-		
-		$dst_file = $this->temp_dir . $uniqname;
-		
-		$objThumb = new gdthumb();
-		$ret = $objThumb->Main($src_file, $width, $height, $dst_file);
-		
-		if($ret[0] != 1) {
-			// ¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸¤ÎÉ½¼¨
-			print($ret[1]);
-			exit;
-		}
-		
-		return basename($ret[1]);
-	}
-		
-	// ¥¢¥Ã¥×¥í¡¼¥É¤µ¤ì¤¿¥Õ¥¡¥¤¥ë¤òÊÝÂ¸¤¹¤ë¡£
-	function makeTempFile($keyname, $rename = true) {
-		$objErr = new SC_CheckError();
-		$cnt = 0;
-		$arrKeyname = array_flip($this->keyname);
-		
-		if(!($_FILES[$keyname]['size'] > 0)) {
-			$objErr->arrErr[$keyname] = "¢¨ " . $this->disp_name[$arrKeyname[$keyname]] . "¤¬¥¢¥Ã¥×¥í¡¼¥É¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£<br />";
-		} else {
-			foreach($this->keyname as $val) {
-				// °ìÃ×¤·¤¿¥­¡¼¤Î¥Õ¥¡¥¤¥ë¤Ë¾ðÊó¤òÊÝÂ¸¤¹¤ë¡£
-				if ($val == $keyname) {
-					// ³ÈÄ¥»Ò¥Á¥§¥Ã¥¯
-					$objErr->doFunc(array($this->disp_name[$cnt], $keyname, $this->arrExt[$cnt]), array("FILE_EXT_CHECK"));
-					// ¥Õ¥¡¥¤¥ë¥µ¥¤¥º¥Á¥§¥Ã¥¯
-					$objErr->doFunc(array($this->disp_name[$cnt], $keyname, $this->size[$cnt]), array("FILE_SIZE_CHECK"));
-					// ¥¨¥é¡¼¤¬¤Ê¤¤¾ì¹ç
-					if(!isset($objErr->arrErr[$keyname])) {
-						// ²èÁü¥Õ¥¡¥¤¥ë¤Î¾ì¹ç
-						if($this->image[$cnt]) {
-							$this->temp_file[$cnt] = $this->makeThumb($_FILES[$keyname]['tmp_name'], $this->width[$cnt], $this->height[$cnt]);
-						// ²èÁü¥Õ¥¡¥¤¥ë°Ê³°¤Î¾ì¹ç
-						} else {
-							// °ì°Õ¤Ê¥Õ¥¡¥¤¥ëÌ¾¤òºîÀ®¤¹¤ë¡£
-							if($rename) {
-								$uniqname = date("mdHi") . "_" . uniqid("").".";
-								$this->temp_file[$cnt] = ereg_replace("^.*\.",$uniqname, $_FILES[$keyname]['name']);
-							} else {
-								$this->temp_file[$cnt] = $_FILES[$keyname]['name'];	
-							}
-							$result  = copy($_FILES[$keyname]['tmp_name'], $this->temp_dir. "/". $this->temp_file[$cnt]);
-							gfPrintLog($_FILES[$keyname]['name']." -> ".$this->temp_dir. "/". $this->temp_file[$cnt]);
-						}
-					}
-				}
-				$cnt++;
-			}
-		}
-		return $objErr->arrErr[$keyname];
-	}
-
-	// ²èÁü¤òºï½ü¤¹¤ë¡£
-	function deleteFile($keyname) {
-		$objImage = new SC_Image($this->temp_dir);
-		$cnt = 0;
-		foreach($this->keyname as $val) {
-			if ($val == $keyname) {
-				// °ì»þ¥Õ¥¡¥¤¥ë¤Î¾ì¹çºï½ü¤¹¤ë¡£
-				if($this->temp_file[$cnt] != "") {
-					$objImage->deleteImage($this->temp_file[$cnt], $this->save_dir);
-				}
-				$this->temp_file[$cnt] = "";
-				$this->save_file[$cnt] = "";
-			}
-			$cnt++;
-		}
-	}
-	
-	// °ì»þ¥Õ¥¡¥¤¥ë¥Ñ¥¹¤ò¼èÆÀ¤¹¤ë¡£
-	function getTempFilePath($keyname) {
-		$cnt = 0;
-		$filepath = "";
-		foreach($this->keyname as $val) {
-			if ($val == $keyname) {
-				if($this->temp_file[$cnt] != "") {
-					$filepath = $this->temp_dir . "/" . $this->temp_file[$cnt];
-				}
-			}
-			$cnt++;
-		}
-		return $filepath;
-	}
-	
-	// °ì»þ¥Õ¥¡¥¤¥ë¤òÊÝÂ¸¥Ç¥£¥ì¥¯¥È¥ê¤Ë°Ü¤¹
-	function moveTempFile() {
-		$cnt = 0;
-		$objImage = new SC_Image($this->temp_dir);
-		
-		foreach($this->keyname as $val) {
-			if($this->temp_file[$cnt] != "") {
-													
-				$objImage->moveTempImage($this->temp_file[$cnt], $this->save_dir);
-				// ¤¹¤Ç¤ËÊÝÂ¸¥Õ¥¡¥¤¥ë¤¬¤¢¤Ã¤¿¾ì¹ç¤Ïºï½ü¤¹¤ë¡£
-				if($this->save_file[$cnt] != "" && !ereg("^sub/", $this->save_file[$cnt])) {
-					$objImage->deleteImage($this->save_file[$cnt], $this->save_dir);
-				}
-			}
-			$cnt++;
-		}
-	}
-	
-	// HIDDENÍÑ¤Î¥Õ¥¡¥¤¥ëÌ¾ÇÛÎó¤òÊÖ¤¹
-	function getHiddenFileList() {
-		$cnt = 0;
-		foreach($this->keyname as $val) {
-			if($this->temp_file[$cnt] != "") {
-				$arrRet["temp_" . $val] = $this->temp_file[$cnt];
-			}
-			if($this->save_file[$cnt] != "") {
-				$arrRet["save_" . $val] = $this->save_file[$cnt];
-			}
-			$cnt++; 
-		}
-		return $arrRet;
-	}
-	
-	// HIDDEN¤ÇÁ÷¤é¤ì¤Æ¤­¤¿¥Õ¥¡¥¤¥ëÌ¾¤ò¼èÆÀ¤¹¤ë
-	function setHiddenFileList($arrPOST) {
-		$cnt = 0;
-		foreach($this->keyname as $val) {
-			$key = "temp_" . $val;
-			if($arrPOST[$key] != "") {
-				$this->temp_file[$cnt] = $arrPOST[$key];
-			}
-			$key = "save_" . $val;
-			if($arrPOST[$key] != "") {
-				$this->save_file[$cnt] = $arrPOST[$key];
-			}
-			$cnt++;
-		}
-	}
-	
-	// ¥Õ¥©¡¼¥à¤ËÅÏ¤¹ÍÑ¤Î¥Õ¥¡¥¤¥ë¾ðÊóÇÛÎó¤òÊÖ¤¹
-	function getFormFileList($temp_url, $save_url, $real_size = false) {
-
-		$cnt = 0;
-		foreach($this->keyname as $val) {
-			if($this->temp_file[$cnt] != "") {
-				// ¥Õ¥¡¥¤¥ë¥Ñ¥¹¥Á¥§¥Ã¥¯(¥Ñ¥¹¤Î¥¹¥é¥Ã¥·¥å/¤¬Ï¢Â³¤·¤Ê¤¤¤è¤¦¤Ë¤¹¤ë¡£)
-				if(ereg("/$", $temp_url)) {
-					$arrRet[$val]['filepath'] = $temp_url . $this->temp_file[$cnt];
-				} else {
-					$arrRet[$val]['filepath'] = $temp_url . "/" . $this->temp_file[$cnt];
-				}
-				$arrRet[$val]['real_filepath'] = $this->temp_dir . $this->temp_file[$cnt];
-			} elseif ($this->save_file[$cnt] != "") {
-				// ¥Õ¥¡¥¤¥ë¥Ñ¥¹¥Á¥§¥Ã¥¯(¥Ñ¥¹¤Î¥¹¥é¥Ã¥·¥å/¤¬Ï¢Â³¤·¤Ê¤¤¤è¤¦¤Ë¤¹¤ë¡£)
-				if(ereg("/$", $save_url)) {
-					$arrRet[$val]['filepath'] = $save_url . $this->save_file[$cnt];
-				} else {
-					$arrRet[$val]['filepath'] = $save_url . "/" . $this->save_file[$cnt];
-				}
-				$arrRet[$val]['real_filepath'] = $this->save_dir . $this->save_file[$cnt];
-			}
-			if($arrRet[$val]['filepath'] != "") {
-				if($real_size){
-					if(is_file($arrRet[$val]['real_filepath'])) {
-						list($width, $height) = getimagesize($arrRet[$val]['real_filepath']);
-					}
-					// ¥Õ¥¡¥¤¥ë²£Éý
-					$arrRet[$val]['width'] = $width;
-					// ¥Õ¥¡¥¤¥ë½ÄÉý
-					$arrRet[$val]['height'] = $height;
-				}else{
-					// ¥Õ¥¡¥¤¥ë²£Éý
-					$arrRet[$val]['width'] = $this->width[$cnt];
-					// ¥Õ¥¡¥¤¥ë½ÄÉý
-					$arrRet[$val]['height'] = $this->height[$cnt];
-				}
-				// É½¼¨Ì¾
-				$arrRet[$val]['disp_name'] = $this->disp_name[$cnt];
-			}
-			$cnt++;
-		}
-		return $arrRet;
-	}
-	
-	// DBÊÝÂ¸ÍÑ¤Î¥Õ¥¡¥¤¥ëÌ¾ÇÛÎó¤òÊÖ¤¹
-	function getDBFileList() {
-		$cnt = 0;
-		foreach($this->keyname as $val) {
-			if($this->temp_file[$cnt] != "") {
-				$arrRet[$val] = $this->temp_file[$cnt];
-			} else  {
-				$arrRet[$val] = $this->save_file[$cnt];
-			}
-			$cnt++;
-		}
-		return $arrRet;
-	}
-	
-	// DB¤ÇÊÝÂ¸¤µ¤ì¤¿¥Õ¥¡¥¤¥ëÌ¾ÇÛÎó¤ò¥»¥Ã¥È¤¹¤ë
-	function setDBFileList($arrVal) {
-		$cnt = 0;
-		foreach($this->keyname as $val) {
-			if($arrVal[$val] != "") {
-				$this->save_file[$cnt] = $arrVal[$val];
-			}
-			$cnt++; 
-		}
-	}
-	
-	// ²èÁü¤ò¥»¥Ã¥È¤¹¤ë
-	function setDBImageList($arrVal) {
-		$cnt = 0;
-		foreach($this->keyname as $val) {
-			if($arrVal[$val] != "" && $val == 'tv_products_image') {
-				$this->save_file[$cnt] = $arrVal[$val];
-			}
-			$cnt++; 
-		}
-	}
-	
-	// DB¾å¤Î¥Õ¥¡¥¤¥ë¤ÎÆâºï½üÍ×µá¤¬¤¢¤Ã¤¿¥Õ¥¡¥¤¥ë¤òºï½ü¤¹¤ë¡£ 
-	function deleteDBFile($arrVal) {
-		$objImage = new SC_Image($this->temp_dir);
-		$cnt = 0;
-		foreach($this->keyname as $val) {
-			if($arrVal[$val] != "") {
-				if($this->save_file[$cnt] == "" && !ereg("^sub/", $arrVal[$val])) {
-					$objImage->deleteImage($arrVal[$val], $this->save_dir);
-				}
-			}
-			$cnt++; 
-		}
-	}
-	
-	// É¬¿ÜÈ½Äê
-	function checkEXISTS($keyname = "") {
-		$cnt = 0;
-		$arrRet = array();
-		foreach($this->keyname as $val) {
-			if($val == $keyname || $keyname == "") {
-				// É¬¿Ü¤Ç¤¢¤ì¤Ð¥¨¥é¡¼¥Á¥§¥Ã¥¯
-				if ($this->necessary[$cnt] == true) {
-					if($this->save_file[$cnt] == "" && $this->temp_file[$cnt] == "") {
-						$arrRet[$val] = "¢¨ " . $this->disp_name[$cnt] . "¤¬¥¢¥Ã¥×¥í¡¼¥É¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£<br>";
-					}
-				}
-			}
-			$cnt++;
-		}
-		return $arrRet;
-	}
-		
-	// ³ÈÂçÎ¨¤ò»ØÄê¤·¤Æ²èÁüÊÝÂ¸
-	function saveResizeImage($keyname, $to_w, $to_h) {
-		$path = "";
-		
-		// keyname¤ÎÅºÉÕ¥Õ¥¡¥¤¥ë¤ò¼èÆÀ
-		$arrImageKey = array_flip($this->keyname);
-		$file = $this->temp_file[$arrImageKey[$keyname]];
-		$filepath = $this->temp_dir . $file;
-		
-		$path = $this->makeThumb($filepath, $to_w, $to_h);
-		
-		// ¥Õ¥¡¥¤¥ëÌ¾¤À¤±ÊÖ¤¹
-		return basename($path);
-	}
+    var $temp_dir;                  // °ì»þ¥Õ¥¡¥¤¥ëÊÝÂ¸¥Ç¥£¥ì¥¯¥È¥ê
+    var $save_dir;                  // ¥Õ¥¡¥¤¥ëÊÝÂ¸¥Ç¥£¥ì¥¯¥È
+    var $ftp_temp_dir;              // FTPÀè°ì»þ¥Ç¥£¥ì¥¯¥È¥ê(Éé²ÙÊ¬»¶»þ»ÈÍÑ)
+    var $ftp_save_dir;              // FTPÀè¥Õ¥¡¥¤¥ëÊÝÂ¸¥Ç¥£¥ì¥¯¥È¥ê(Éé²ÙÊ¬»¶»þ»ÈÍÑ)
+    var $multi_web_server_mode;     // Éé²ÙÊ¬»¶¥Õ¥é¥°(Éé²ÙÊ¬»¶»þ»ÈÍÑ)
+    var $keyname;                   // ¥Õ¥¡¥¤¥ëinput¥¿¥°¤Îname
+    var $width;                     // ²£¥µ¥¤¥º
+    var $height;                    // ½Ä¥µ¥¤¥º
+    var $arrExt;                    // »ØÄê¤¹¤ë³ÈÄ¥»Ò
+    var $temp_file;                 // ÊÝÂ¸¤µ¤ì¤¿¥Õ¥¡¥¤¥ëÌ¾
+    var $save_file;                 // DB¤«¤éÆÉ¤ß½Ð¤·¤¿¥Õ¥¡¥¤¥ëÌ¾
+    var $disp_name;                 // ¹àÌÜÌ¾
+    var $size;                      // À©¸Â¥µ¥¤¥º
+    var $necessary;                 // É¬¿Ü¤Î¾ì¹ç:true
+    var $image;                     // ²èÁü¤Î¾ì¹ç:true
+
+    // ¥Õ¥¡¥¤¥ë´ÉÍý¥¯¥é¥¹
+    function SC_UploadFile($temp_dir, $save_dir, $ftp_temp_dir = "", $ftp_save_dir = "", $multi_web_server_mode = false) {
+        $this->temp_dir = $temp_dir;
+        $this->save_dir = $save_dir;
+        $this->ftp_temp_dir = $ftp_temp_dir;
+        $this->ftp_save_dir = $ftp_save_dir;
+        $this->multi_web_server_mode = $multi_web_server_mode;
+        $this->file_max = 0;
+    }
+
+    // ¥Õ¥¡¥¤¥ë¾ðÊóÄÉ²Ã
+    function addFile($disp_name, $keyname, $arrExt, $size, $necessary=false, $width=0, $height=0, $image=true) {
+        $this->disp_name[] = $disp_name;
+        $this->keyname[] = $keyname;
+        $this->width[] = $width;
+        $this->height[] = $height;
+        $this->arrExt[] = $arrExt;
+        $this->size[] = $size;
+        $this->necessary[] = $necessary;
+        $this->image[] = $image;
+    }
+    // ¥µ¥à¥Í¥¤¥ë²èÁü¤ÎºîÀ®
+    function makeThumb($src_file, $width, $height) {
+        // °ì°Õ¤ÊID¤ò¼èÆÀ¤¹¤ë¡£
+        $uniqname = date("mdHi") . "_" . uniqid("");
+        
+        $objThumb = new gdthumb();
+        
+        // WEB¥µ¡¼¥ÐÉé²ÙÊ¬»¶´Ä¶­¤Î¾ì¹ç
+        if($this->multi_web_server_mode === true) {
+            
+            // FTPÍÑ¥Õ¥¡¥¤¥ë°ì»þ³ÊÇ¼ÍÑ¥Ç¥£¥ì¥¯¥È¥êºîÀ®
+            $ftp_temp_dir = $this->makeFtpTempDir($this->temp_dir);
+            $dst_file = $ftp_temp_dir . $uniqname;
+            $ret = $objThumb->Main($src_file, $width, $height, $dst_file);
+            $this->ftpMoveFile($this->ftp_temp_dir . basename($ret[1]), $ret[1], true);
+        } else {
+            $dst_file = $this->temp_dir . $uniqname;
+            $ret = $objThumb->Main($src_file, $width, $height, $dst_file);          
+        }
+        
+        if($ret[0] != 1) {
+            // ¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸¤ÎÉ½¼¨
+            print($ret[1]);
+            exit;
+        }
+        
+        return basename($ret[1]);
+    }
+        
+    // ¥¢¥Ã¥×¥í¡¼¥É¤µ¤ì¤¿¥Õ¥¡¥¤¥ë¤òÊÝÂ¸¤¹¤ë¡£
+    function makeTempFile($keyname, $rename = true) {
+        $objErr = new SC_CheckError();
+        $cnt = 0;
+        $arrKeyname = array_flip($this->keyname);
+        
+        if(!($_FILES[$keyname]['size'] > 0)) {
+            $objErr->arrErr[$keyname] = "¢¨ " . $this->disp_name[$arrKeyname[$keyname]] . "¤¬¥¢¥Ã¥×¥í¡¼¥É¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£<br />";
+        } else {
+            foreach($this->keyname as $val) {
+                // °ìÃ×¤·¤¿¥­¡¼¤Î¥Õ¥¡¥¤¥ë¤Ë¾ðÊó¤òÊÝÂ¸¤¹¤ë¡£
+                if ($val == $keyname) {
+                    // ³ÈÄ¥»Ò¥Á¥§¥Ã¥¯
+                    $objErr->doFunc(array($this->disp_name[$cnt], $keyname, $this->arrExt[$cnt]), array("FILE_EXT_CHECK"));
+                    // ¥Õ¥¡¥¤¥ë¥µ¥¤¥º¥Á¥§¥Ã¥¯
+                    $objErr->doFunc(array($this->disp_name[$cnt], $keyname, $this->size[$cnt]), array("FILE_SIZE_CHECK"));
+                    // ¥¨¥é¡¼¤¬¤Ê¤¤¾ì¹ç
+                    if(!isset($objErr->arrErr[$keyname])) {
+                        // ²èÁü¥Õ¥¡¥¤¥ë¤Î¾ì¹ç
+                        if($this->image[$cnt]) {
+                            $this->temp_file[$cnt] = $this->makeThumb($_FILES[$keyname]['tmp_name'], $this->width[$cnt], $this->height[$cnt]);
+                        // ²èÁü¥Õ¥¡¥¤¥ë°Ê³°¤Î¾ì¹ç
+                        } else {
+                            // °ì°Õ¤Ê¥Õ¥¡¥¤¥ëÌ¾¤òºîÀ®¤¹¤ë¡£
+                            if($rename) {
+                                $uniqname = date("mdHi") . "_" . uniqid("").".";
+                                $this->temp_file[$cnt] = ereg_replace("^.*\.",$uniqname, $_FILES[$keyname]['name']);
+                            } else {
+                                $this->temp_file[$cnt] = $_FILES[$keyname]['name'];    
+                            }
+                            $result  = copy($_FILES[$keyname]['tmp_name'], $this->temp_dir. "/". $this->temp_file[$cnt]);
+                            gfPrintLog($_FILES[$keyname]['name']." -> ".$this->temp_dir. "/". $this->temp_file[$cnt]);
+                        }
+                    }
+                }
+                $cnt++;
+            }
+        }
+        return $objErr->arrErr[$keyname];
+    }
+
+    // ²èÁü¤òºï½ü¤¹¤ë¡£
+    function deleteFile($keyname) {
+        $objImage = new SC_Image($this->temp_dir);
+        $cnt = 0;
+        foreach($this->keyname as $val) {
+            if ($val == $keyname) {
+                // °ì»þ¥Õ¥¡¥¤¥ë¤Î¾ì¹çºï½ü¤¹¤ë¡£
+                if($this->temp_file[$cnt] != "") {
+                    // Éé²ÙÊ¬»¶»þ¤Ï¤¹¤Ù¤Æ¤Î¥µ¡¼¥Ð¤«¤éºï½ü
+                    if($this->multi_web_server_mode === true) {
+                        $this->ftpDeleteFile($this->ftp_temp_dir . $this->temp_file[$cnt]);
+                    } else {
+                        $objImage->deleteImage($this->temp_file[$cnt], $this->save_dir);
+                    }
+                }
+                $this->temp_file[$cnt] = "";
+                $this->save_file[$cnt] = "";
+            }
+            $cnt++;
+        }
+    }
+    
+    // °ì»þ¥Õ¥¡¥¤¥ë¥Ñ¥¹¤ò¼èÆÀ¤¹¤ë¡£
+    function getTempFilePath($keyname) {
+        $cnt = 0;
+        $filepath = "";
+        foreach($this->keyname as $val) {
+            if ($val == $keyname) {
+                if($this->temp_file[$cnt] != "") {
+                    $filepath = $this->temp_dir . "/" . $this->temp_file[$cnt];
+                }
+            }
+            $cnt++;
+        }
+        return $filepath;
+    }
+    
+    // °ì»þ¥Õ¥¡¥¤¥ë¤òÊÝÂ¸¥Ç¥£¥ì¥¯¥È¥ê¤Ë°Ü¤¹
+    function moveTempFile() {
+        $cnt = 0;
+        $objImage = new SC_Image($this->temp_dir);
+        
+        foreach($this->keyname as $val) {
+            if($this->temp_file[$cnt] != "") {
+                // Éé²ÙÊ¬»¶»þ¤Ï¤¹¤Ù¤Æ¤Î¥µ¡¼¥Ð¤Ç°ÜÆ°¤ò¼Â¹Ô
+                if($this->multi_web_server_mode === true) {
+                    $dist_path = $this->ftp_save_dir . $this->temp_file[$cnt];
+                    $src_path = $this->temp_dir . $this->temp_file[$cnt];
+                    $this->ftpMoveFile($dist_path, $src_path);
+                } else {
+                    $objImage->moveTempImage($this->temp_file[$cnt], $this->save_dir);
+                }
+                
+                // ¤¹¤Ç¤ËÊÝÂ¸¥Õ¥¡¥¤¥ë¤¬¤¢¤Ã¤¿¾ì¹ç¤Ïºï½ü¤¹¤ë¡£
+                if($this->save_file[$cnt] != "" && !ereg("^sub/", $this->save_file[$cnt])) {
+                    // Éé²ÙÊ¬»¶»þ¤Ï¤¹¤Ù¤Æ¤Î¥µ¡¼¥Ð¤Ç¥Õ¥¡¥¤¥ëºï½ü
+                    if($this->multi_web_server_mode === true) {
+                        $this->ftpDeleteFile($this->ftp_save_dir . $this->save_file[$cnt]);
+                    } else {
+                        $objImage->deleteImage($this->save_file[$cnt], $this->save_dir);
+                    }
+                }
+            }
+            $cnt++;
+        }
+    }
+    
+    // HIDDENÍÑ¤Î¥Õ¥¡¥¤¥ëÌ¾ÇÛÎó¤òÊÖ¤¹
+    function getHiddenFileList() {
+        $cnt = 0;
+        foreach($this->keyname as $val) {
+            if($this->temp_file[$cnt] != "") {
+                $arrRet["temp_" . $val] = $this->temp_file[$cnt];
+            }
+            if($this->save_file[$cnt] != "") {
+                $arrRet["save_" . $val] = $this->save_file[$cnt];
+            }
+            $cnt++; 
+        }
+        return $arrRet;
+    }
+    
+    // HIDDEN¤ÇÁ÷¤é¤ì¤Æ¤­¤¿¥Õ¥¡¥¤¥ëÌ¾¤ò¼èÆÀ¤¹¤ë
+    function setHiddenFileList($arrPOST) {
+        $cnt = 0;
+        foreach($this->keyname as $val) {
+            $key = "temp_" . $val;
+            if($arrPOST[$key] != "") {
+                $this->temp_file[$cnt] = $arrPOST[$key];
+            }
+            $key = "save_" . $val;
+            if($arrPOST[$key] != "") {
+                $this->save_file[$cnt] = $arrPOST[$key];
+            }
+            $cnt++;
+        }
+    }
+    
+    // ¥Õ¥©¡¼¥à¤ËÅÏ¤¹ÍÑ¤Î¥Õ¥¡¥¤¥ë¾ðÊóÇÛÎó¤òÊÖ¤¹
+    function getFormFileList($temp_url, $save_url, $real_size = false) {
+
+        $cnt = 0;
+        foreach($this->keyname as $val) {
+            if($this->temp_file[$cnt] != "") {
+                // ¥Õ¥¡¥¤¥ë¥Ñ¥¹¥Á¥§¥Ã¥¯(¥Ñ¥¹¤Î¥¹¥é¥Ã¥·¥å/¤¬Ï¢Â³¤·¤Ê¤¤¤è¤¦¤Ë¤¹¤ë¡£)
+                if(ereg("/$", $temp_url)) {
+                    $arrRet[$val]['filepath'] = $temp_url . $this->temp_file[$cnt];
+                } else {
+                    $arrRet[$val]['filepath'] = $temp_url . "/" . $this->temp_file[$cnt];
+                }
+                $arrRet[$val]['real_filepath'] = $this->temp_dir . $this->temp_file[$cnt];
+            } elseif ($this->save_file[$cnt] != "") {
+                // ¥Õ¥¡¥¤¥ë¥Ñ¥¹¥Á¥§¥Ã¥¯(¥Ñ¥¹¤Î¥¹¥é¥Ã¥·¥å/¤¬Ï¢Â³¤·¤Ê¤¤¤è¤¦¤Ë¤¹¤ë¡£)
+                if(ereg("/$", $save_url)) {
+                    $arrRet[$val]['filepath'] = $save_url . $this->save_file[$cnt];
+                } else {
+                    $arrRet[$val]['filepath'] = $save_url . "/" . $this->save_file[$cnt];
+                }
+                $arrRet[$val]['real_filepath'] = $this->save_dir . $this->save_file[$cnt];
+            }
+            if($arrRet[$val]['filepath'] != "") {
+                if($real_size){
+                    if(is_file($arrRet[$val]['real_filepath'])) {
+                        list($width, $height) = getimagesize($arrRet[$val]['real_filepath']);
+                    }
+                    // ¥Õ¥¡¥¤¥ë²£Éý
+                    $arrRet[$val]['width'] = $width;
+                    // ¥Õ¥¡¥¤¥ë½ÄÉý
+                    $arrRet[$val]['height'] = $height;
+                }else{
+                    // ¥Õ¥¡¥¤¥ë²£Éý
+                    $arrRet[$val]['width'] = $this->width[$cnt];
+                    // ¥Õ¥¡¥¤¥ë½ÄÉý
+                    $arrRet[$val]['height'] = $this->height[$cnt];
+                }
+                // É½¼¨Ì¾
+                $arrRet[$val]['disp_name'] = $this->disp_name[$cnt];
+            }
+            $cnt++;
+        }
+        return $arrRet;
+    }
+    
+    // DBÊÝÂ¸ÍÑ¤Î¥Õ¥¡¥¤¥ëÌ¾ÇÛÎó¤òÊÖ¤¹
+    function getDBFileList() {
+        $cnt = 0;
+        foreach($this->keyname as $val) {
+            if($this->temp_file[$cnt] != "") {
+                $arrRet[$val] = $this->temp_file[$cnt];
+            } else  {
+                $arrRet[$val] = $this->save_file[$cnt];
+            }
+            $cnt++;
+        }
+        return $arrRet;
+    }
+    
+    // DB¤ÇÊÝÂ¸¤µ¤ì¤¿¥Õ¥¡¥¤¥ëÌ¾ÇÛÎó¤ò¥»¥Ã¥È¤¹¤ë
+    function setDBFileList($arrVal) {
+        $cnt = 0;
+        foreach($this->keyname as $val) {
+            if($arrVal[$val] != "") {
+                $this->save_file[$cnt] = $arrVal[$val];
+            }
+            $cnt++; 
+        }
+    }
+    
+    // ²èÁü¤ò¥»¥Ã¥È¤¹¤ë
+    function setDBImageList($arrVal) {
+        $cnt = 0;
+        foreach($this->keyname as $val) {
+            if($arrVal[$val] != "" && $val == 'tv_products_image') {
+                $this->save_file[$cnt] = $arrVal[$val];
+            }
+            $cnt++; 
+        }
+    }
+    
+    // DB¾å¤Î¥Õ¥¡¥¤¥ë¤ÎÆâºï½üÍ×µá¤¬¤¢¤Ã¤¿¥Õ¥¡¥¤¥ë¤òºï½ü¤¹¤ë¡£ 
+    function deleteDBFile($arrVal) {
+        $objImage = new SC_Image($this->temp_dir);
+        $cnt = 0;
+        foreach($this->keyname as $val) {
+            if($arrVal[$val] != "") {
+                if($this->save_file[$cnt] == "" && !ereg("^sub/", $arrVal[$val])) {
+                    
+                    // Éé²ÙÊ¬»¶»þ¤Ï¤¹¤Ù¤Æ¤Î¥µ¡¼¥Ð¤Ç¥Õ¥¡¥¤¥ëºï½ü
+                    if($this->multi_web_server_mode === true) {
+                        $this->ftpDeleteFile($this->ftp_save_dir . $arrVal[$val]);
+                    } else {
+                        $objImage->deleteImage($arrVal[$val], $this->save_dir);
+                    }
+                }
+            }
+            $cnt++; 
+        }
+    }
+    
+    // É¬¿ÜÈ½Äê
+    function checkEXISTS($keyname = "") {
+        $cnt = 0;
+        $arrRet = array();
+        foreach($this->keyname as $val) {
+            if($val == $keyname || $keyname == "") {
+                // É¬¿Ü¤Ç¤¢¤ì¤Ð¥¨¥é¡¼¥Á¥§¥Ã¥¯
+                if ($this->necessary[$cnt] == true) {
+                    if($this->save_file[$cnt] == "" && $this->temp_file[$cnt] == "") {
+                        $arrRet[$val] = "¢¨ " . $this->disp_name[$cnt] . "¤¬¥¢¥Ã¥×¥í¡¼¥É¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£<br>";
+                    }
+                }
+            }
+            $cnt++;
+        }
+        return $arrRet;
+    }
+        
+    // ³ÈÂçÎ¨¤ò»ØÄê¤·¤Æ²èÁüÊÝÂ¸
+    function saveResizeImage($keyname, $to_w, $to_h) {
+        $path = "";
+        
+        // keyname¤ÎÅºÉÕ¥Õ¥¡¥¤¥ë¤ò¼èÆÀ
+        $arrImageKey = array_flip($this->keyname);
+        $file = $this->temp_file[$arrImageKey[$keyname]];
+        $filepath = $this->temp_dir . $file;
+        
+        $path = $this->makeThumb($filepath, $to_w, $to_h);
+        
+        // ¥Õ¥¡¥¤¥ëÌ¾¤À¤±ÊÖ¤¹
+        return basename($path);
+    }
+
+    /**         
+     * ¥Õ¥¡¥¤¥ë¤òÁ´¤Æ¤ÎWEB¥µ¡¼¥Ð¤Ø¥³¥Ô¡¼
+     *
+     * @param string $dst_path ¥³¥Ô¡¼Àè¥Õ¥¡¥¤¥ë¥Ñ¥¹(ÁêÂÐ¥Ñ¥¹)
+     * @param string $src_path ¥³¥Ô¡¼¸µ¥Õ¥¡¥¤¥ë¥Ñ¥¹(ÀäÂÐ¥Ñ¥¹)
+     * @param boolean $del_flag °ÜÆ°¥Õ¥¡¥¤¥ë¤òºï½ü¤¹¤ë¥Õ¥é¥°
+     * @return void
+     */
+    function ftpMoveFile($dst_path, $src_path, $del_flag = false) {
+        global $arrWEB_SERVERS;
+
+        // Á´¤Æ¤Î¥µ¡¼¥Ð¤Ë¥Õ¥¡¥¤¥ë¤ò¥³¥Ô¡¼¤¹¤ë
+        foreach($arrWEB_SERVERS as $array) {
+            sfFtpCopy($array['host'], $array['user'], $array['pass'], $dst_path, $src_path);
+        }
+        // °ÜÆ°¸å¤Ï¥Õ¥¡¥¤¥ë¤òºï½ü
+        if($del_flag === true) {
+            @unlink($src_path);
+        }
+    }
+
+    /**         
+     * ¥Õ¥¡¥¤¥ë¤òÁ´¤Æ¤ÎWEB¥µ¡¼¥Ð¾å¤«¤éºï½ü
+     *
+     * @param string $dst_path ¥³¥Ô¡¼Àè¥Õ¥¡¥¤¥ë¥Ñ¥¹(ÁêÂÐ¥Ñ¥¹)
+     * @return void
+     */
+    function ftpDeleteFile($dst_path) {
+        global $arrWEB_SERVERS;
+
+        // Á´¤Æ¤Î¥µ¡¼¥Ð¤Ë¥Õ¥¡¥¤¥ë¤ò¥³¥Ô¡¼¤¹¤ë
+        foreach($arrWEB_SERVERS as $array) {
+            sfFtpDelete($array['host'], $array['user'], $array['pass'], $dst_path);
+        }
+    }
+
+
+    /**
+     * FTPÍÑ¥Õ¥¡¥¤¥ë°ì»þ³ÊÇ¼¥Ç¥£¥ì¥¯¥È¥êºîÀ®
+     *
+     * @param string $dir ºîÀ®¥Ç¥£¥ì¥¯¥È¥ê
+     * @return string $ftp_temp_dir ºîÀ®°ì»þ³ÊÇ¼¥Ç¥£¥ì¥¯¥È¥ê¥Ñ¥¹
+     */
+    function makeFtpTempDir($dir) {
+        // FTPÍÑ¥Õ¥¡¥¤¥ë°ì»þ³ÊÇ¼ÍÑ¥Ç¥£¥ì¥¯¥È¥ê
+        $ftp_temp_dir = $this->temp_dir . "ftp_temp/";
+        // ¥Ç¥£¥ì¥¯¥È¥ê¤¬Â¸ºß¤·¤Ê¤«¤Ã¤¿¤éºîÀ®
+        if(!file_exists($ftp_temp_dir)) {
+            mkdir($ftp_temp_dir);
+            chmod($ftp_temp_dir, 0777);
+        }
+        
+        return $ftp_temp_dir;
+    }
 }
 ?>
Index: branches/beta/data/class/SC_CartSession.php
===================================================================
--- branches/beta/data/class/SC_CartSession.php	(revision 11907)
+++ branches/beta/data/class/SC_CartSession.php	(revision 14676)
@@ -173,5 +173,5 @@
 	
 	// ¥«¡¼¥È¤Ø¤Î¾¦ÉÊÄÉ²Ã
-	function addProduct($id, $quantity) {
+	function addProduct($id, $quantity, $campaign_id = "") {
 		$find = false;
 		$max = $this->getMax();
@@ -182,4 +182,8 @@
 				if(strlen($val) <= INT_LEN) {
 					$_SESSION[$this->key][$i]['quantity']+= $quantity;
+                    if(!empty($campaign_id)){
+                        $_SESSION[$this->key][$i]['campaign_id'] = $campaign_id;
+                        $_SESSION[$this->key][$i]['is_campaign'] = true;
+                    }
 				}
 				$find = true;
@@ -190,4 +194,8 @@
 			$_SESSION[$this->key][$max+1]['quantity'] = $quantity;
 			$_SESSION[$this->key][$max+1]['cart_no'] = $this->getNextCartID();
+            if(!empty($campaign_id)){
+                $_SESSION[$this->key][$max+1]['campaign_id'] = $campaign_id;
+                $_SESSION[$this->key][$max+1]['is_campaign'] = true;
+            }
 		}
 	}
@@ -322,5 +330,20 @@
 		}
 	}
-	
+    
+    /**
+     * ¥«¡¼¥È¤ÎÃæ¤Î¥­¥ã¥ó¥Ú¡¼¥ó¾¦ÉÊ¤Î¥Á¥§¥Ã¥¯
+     * @param integer $campaign_id ¥­¥ã¥ó¥Ú¡¼¥óID
+     * @return boolean True:¥­¥ã¥ó¥Ú¡¼¥ó¾¦ÉÊÍ­¤ê False:¥­¥ã¥ó¥Ú¡¼¥ó¾¦ÉÊÌµ¤·
+     */
+	function chkCampaign($campaign_id){
+		$max = $this->getMax();
+		for($i = 0; $i <= $max; $i++) {
+			if($_SESSION[$this->key][$i]['is_campaign'] and $_SESSION[$this->key][$i]['campaign_id'] == $campaign_id) return true;
+		}
+        
+		return false;
+	}
+    
+
 }
 ?>
Index: branches/beta/data/class/SC_CustomerList.php
===================================================================
--- branches/beta/data/class/SC_CustomerList.php	(revision 11771)
+++ branches/beta/data/class/SC_CustomerList.php	(revision 14676)
@@ -5,5 +5,6 @@
  * http://www.lockon.co.jp/
  */
-
+$INC_PATH = realpath( dirname( __FILE__) );
+require( $INC_PATH ."/../conf/conf.php" );
 /*  [Ì¾¾Î] SC_CustomerList
  *  [³µÍ×] ²ñ°÷¸¡º÷ÍÑ¥¯¥é¥¹
@@ -191,14 +192,43 @@
 			$this->setWhere($sql_where);
 		}
-				
-		//¡¡ÇÛ¿®¥á¡¼¥ë¥¢¥É¥ì¥¹¼ïÊÌ
-		if ( $mode == 'magazine' ){
-			if ( strlen($this->arrSql['mail_type']) > 0 && $this->arrSql['mail_type'] == 2) {
-				$this->setWhere( " dtb_customer.email_mobile <> ''  ");
-			}
-		}
-							
-		//¡¡HTML-mail
-		if ( $mode == 'magazine' ){
+
+/*      2007/05/28  °ìÃ¶¡¢Ää»ß¤·¤Þ¤¹¡£				
+ *		//¡¡ÇÛ¿®¥á¡¼¥ë¥¢¥É¥ì¥¹¼ïÊÌ
+ *		if ( $mode == 'magazine' ){
+ *			if ( strlen($this->arrSql['mail_type']) > 0 && $this->arrSql['mail_type'] == 2) {
+ *				$this->setWhere( " dtb_customer.email_mobile <> ''  ");
+ *			}
+ *		}
+ */
+
+        if($mode == 'magazine'){
+        	global $arrDomainType;
+        	$sql_where = "";
+        	//¥É¥á¥¤¥ó»ØÄê¡££±¤Ï£Ð£Ã¡¢£²¤Ï·ÈÂÓ
+        	if ( $this->arrSql['domain'] > 0 ) {
+        		foreach($arrDomainType as $val) {
+        			if($this->arrSql['domain'] == 1) {
+        				if($sql_where == "") {
+        					$sql_where .= "dtb_customer.email NOT ILIKE ? ";
+        				} else {
+        					$sql_where .= "AND dtb_customer.email NOT ILIKE ? " ;
+        				}
+        			} elseif($this->arrSql['domain'] == 2) {
+        				if($sql_where == "") {
+        					$sql_where .= "dtb_customer.email ILIKE ? ";
+        				} else {
+        					$sql_where .= "OR dtb_customer.email LIKE ? " ;
+        				}
+                        $sql_where = "(".$sql_where.")";
+        			}
+        			$searchDomain = $this->addSearchStr($val);
+        			$this->arrVal[] = $searchDomain;
+        		}
+        	    $this->setWhere($sql_where);
+        	}
+        }
+
+		//¡¡HTML-mail¡ÊÇÛ¿®Êý¼°)
+		if( $mode == 'magazine' ){
 			if ( strlen($this->arrSql['htmlmail']) > 0 ) {
 				$this->setWhere( " mailmaga_flg = ? ");
Index: branches/beta/data/class/SC_SelectSql.php
===================================================================
--- branches/beta/data/class/SC_SelectSql.php	(revision 11917)
+++ branches/beta/data/class/SC_SelectSql.php	(revision 14676)
@@ -27,5 +27,5 @@
 	}
 
-	//-- SQLÊ¬À¸À®
+	//-- SQLÊ¸À¸À®
 	function getSql( $mode = "" ){
 		$this->sql = $this->select ." ". $this->where ." ". $this->group ." ";
@@ -196,5 +196,5 @@
 		}
 	}
-
+	
 	function setOrder($order){
 		
Index: branches/beta/data/class/SC_DbConn.php
===================================================================
--- branches/beta/data/class/SC_DbConn.php	(revision 13370)
+++ branches/beta/data/class/SC_DbConn.php	(revision 14676)
@@ -112,5 +112,5 @@
 				sfErrorHeader("DB¤Ø¤ÎÀÜÂ³¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£:" . $this->dsn);
 			}else{
-				sfErrorHeader("DB¤Ø¤ÎÀÜÂ³¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£:");
+				sfErrorHeader("DB¤Ø¤ÎÀÜÂ³¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£");
 			}
 			return 0;
@@ -167,22 +167,33 @@
 	}
 
-    function send_err_mail( $result, $sql ){
-        
-        if ($this->err_disp && DEBUG_MODE) {
-            if ($_SERVER['HTTPS'] == "on") {
-                $url = "https://";
-            } else {
-                $url = "http://";
-            }
-            $url.= $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
-            
-            $errmsg = $url."\n\n";
-            $errmsg.= $sql . "\n";
-            $errmsg.= $result->message . "\n\n";
-            $errmsg.= $result->userinfo . "\n\n";
+    function debug_print($result, $sql){
+        $this->send_err_mail($result, $sql);
+    }
+    
+    function send_err_mail($result, $sql){
+        $url = '';
+        $errmsg = '';
+        
+        if ($_SERVER['HTTPS'] == "on") {
+            $url = "https://";
+        } else {
+            $url = "http://";
+        }
+        $url .= $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
+        
+        $errmsg  = $url."\n\n";
+        $errmsg .= $sql . "\n";
+        $errmsg .= $result->message . "\n\n";
+        $errmsg .= $result->userinfo . "\n\n";
+        
+        if ($this->err_disp && DEBUG_MODE === true) {
+            print('<pre>');
             print_r(htmlspecialchars($errmsg, ENT_QUOTES, CHAR_CODE));
-
-            exit();
+            print('</pre>');
         }
+        
+        gfDebugLog($errmsg, DB_ERR_LOG_PATH);
+        
+        exit();
     }
 }
Index: branches/beta/data/class/SC_Query.php
===================================================================
--- branches/beta/data/class/SC_Query.php	(revision 337)
+++ branches/beta/data/class/SC_Query.php	(revision 14676)
@@ -1,4 +1,4 @@
 <?php
-/*
+/**
  * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
  *
@@ -6,55 +6,141 @@
  */
 
+/**
+ *  SC_Query¥¯¥é¥¹
+ *
+ *  @author     LOCKON CO.,LTD.
+ *  @access     public
+ */
 class SC_Query {
-	var $option;
-	var $where;
-	var $conn;
-	var $groupby;
-	var $order;
-	
-	// ¥³¥ó¥¹¥È¥é¥¯¥¿
-	/*
-		$err_disp:¥¨¥é¡¼É½¼¨¤ò¹Ô¤¦¤«
-		$new¡§¿·µ¬¤ËÀÜÂ³¤ò¹Ô¤¦¤«
-	 */
-	function SC_Query($dsn = "", $err_disp = true, $new = false) {
-		$this->conn = new SC_DBconn($dsn, $err_disp, $new);
-		$this->where = "";
-		return $this->conn;
-	}
-	
-	// ¥¨¥é¡¼È½Äê
-	function isError() {
-		if(PEAR::isError($this->conn->conn)) {
-			return true;
-		}
-		return false;
-	}
-	
-	// COUNTÊ¸¤Î¼Â¹Ô
-	function count($table, $where = "", $arrval = array()) {
-		if(strlen($where) <= 0) {
-			$sqlse = "SELECT COUNT(*) FROM $table";
-		} else {
-			$sqlse = "SELECT COUNT(*) FROM $table WHERE $where";
-		}
-		// ¥«¥¦¥ó¥ÈÊ¸¤Î¼Â¹Ô
-		$ret = $this->conn->getOne($sqlse, $arrval);
-		return $ret;
-	}
-	
-	function select($col, $table, $where = "", $arrval = array()){
-		$sqlse = $this->getsql($col, $table, $where);
-		$ret = $this->conn->getAll($sqlse, $arrval);
-		return $ret;
-	}
-
-	function getLastQuery($disp = true) {
-		$sql = $this->conn->conn->last_query;
-		if($disp) { 
-			print($sql.";<br />\n");
-		}
-		return $sql;
-	}
+   /**#@+
+    * @access private
+    */
+    
+   /**
+    * SC_DBConn¥ª¥Ö¥¸¥§¥¯¥È
+    * @var SC_DBConn
+    */
+    var $conn;
+    
+   /**
+    * LIMIT,OFFSET ¶ç
+    * @var string
+    */
+    var $option;
+    
+   /**
+    * WHERE ¶ç
+    * @var string
+    */
+    var $where;
+    
+   /**
+    * GROUP BY ¶ç
+    * @var string
+    */
+    var $groupby;
+    
+   /**
+    * ORDER BY ¶ç
+    * @var string
+    */
+    var $order;
+    
+    /**#@-*/
+    
+    /**
+     *  SC_Query¥¯¥é¥¹¤Î¥³¥ó¥¹¥È¥é¥¯¥¿
+     *
+     *  @access public
+     *  @param  string  $dsn      DSN¾ðÊó
+     *  @param  boolean $err_disp ¥¨¥é¡¼É½¼¨¤ò¹Ô¤¦¤«¤É¤¦¤«
+     *  @param  boolean $new      ¿·µ¬¤ËDBÀÜÂ³¤ò¹Ô¤¦¤«¤É¤¦¤«
+     */
+    function SC_Query($dsn = "", $err_disp = true, $new = false) {
+        $this->conn = new SC_DBconn($dsn, $err_disp, $new);
+        $this->where   = "";
+        $this->option  = "";
+        $this->groupby = "";
+        return $this->conn; //?
+    }
+    
+    /**
+     *  DB¥¨¥é¡¼¤ÎÈ½Äê
+     *
+     *  @access public
+     *  @return boolean À®¸ù»þ¡§true ¼ºÇÔ»þ¡§false
+     */
+    function isError() {
+        if(PEAR::isError($this->conn->conn)) {
+            return true;
+        }
+        return false;
+    }
+    
+    /**
+     *  ¥ª¥×¥·¥ç¥ó¤Î½é´ü²½
+     *
+     *  @access public
+     *  @return void
+     */
+    function clear(){
+        $arrProperty = array_keys((get_object_vars($this)));
+        foreach ( $arrProperty as $property ) {
+            if ($property != 'conn') {
+                $this->$property = '';
+            }
+        }
+    }
+    
+    /**
+     *  COUNTÊ¸¤Î¼Â¹Ô
+     *
+     *  @access public
+     *  @param  string  $table  ¥Æ¡¼¥Ö¥ëÌ¾
+     *  @param  string  $where  WHERE¶ç
+     *  @param  array   $arrval ¥×¥ì¡¼¥¹¥Û¥ë¥À¤ÎÇÛÎó
+     *  @return string  ¥ì¥³¡¼¥É·ï¿ô
+     */
+    function count($table, $where = "", $arrval = array()) {
+        if(strlen($where) <= 0) {
+            $sqlse = "SELECT COUNT(*) FROM $table";
+        } else {
+            $sqlse = "SELECT COUNT(*) FROM $table WHERE $where";
+        }
+        // ¥«¥¦¥ó¥ÈÊ¸¤Î¼Â¹Ô
+        $ret = $this->conn->getOne($sqlse, $arrval);
+        return $ret;
+    }
+    
+    /**
+     *  SELECTÊ¸¤Î¼Â¹Ô
+     *
+     *  @access public
+     *  @param  string  $col    ¥«¥é¥àÌ¾
+     *  @param  string  $table  ¥Æ¡¼¥Ö¥ëÌ¾
+     *  @param  string  $where  WHERE¶ç
+     *  @param  array   $arrval ¥×¥ì¡¼¥¹¥Û¥ë¥À¤ÎÇÛÎó
+     *  @return array   SELECTÊ¸¤Î¼Â¹Ô·ë²Ì
+     */
+    function select($col, $table, $where = "", $arrval = array()){
+        $sqlse = $this->getsql($col, $table, $where);
+        $ret = $this->conn->getAll($sqlse, $arrval);
+        return $ret;
+    }
+    
+    /**
+     *  ºÇ¸å¤Ë¼Â¹Ô¤·¤¿SQLÊ¸¤ò¼èÆÀ¤¹¤ë
+     *
+     *  @access public
+     *  @param  boolean $disp SQLÊ¸¤òprint¤¹¤ë¤«¤É¤¦¤«
+     *  @return string  $disp==false¤Î¾ì¹ç¡§ºÇ¸å¤Ë¼Â¹Ô¤·¤¿SQLÊ¸¡¡$disp==true¤Î¾ì¹ç¡§¤Ê¤·
+     */
+    function getLastQuery($disp = true) {
+        $sql = $this->conn->conn->last_query;
+        if($disp) { 
+            print($sql.";<br />\n");
+        }
+        return $sql;
+    }
 
 	function commit() {
@@ -105,81 +191,157 @@
 	}
 
-	function getsql($col, $table, $where) {
-		if($where != "") {
-			// °ú¿ô¤Î$where¤òÍ¥Àè¤·¤Æ¼Â¹Ô¤¹¤ë¡£
-			$sqlse = "SELECT $col FROM $table WHERE $where " . $this->groupby . " " . $this->order . " " . $this->option;
-		} else {
-			if($this->where != "") {
-					$sqlse = "SELECT $col FROM $table WHERE $this->where " . $this->groupby . " " . $this->order . " " . $this->option;
-				} else {
-					$sqlse = "SELECT $col FROM $table " . $this->groupby . " " . $this->order . " " . $this->option;
-			}
-		}
-		return $sqlse;
-	}
-			
-	function setoption($str) {
-		$this->option = $str;
-	}
-	
-	function setlimitoffset($limit, $offset = 0, $return = false) {
-		if (is_numeric($limit) && is_numeric($offset)){
-			
-			$option.= " LIMIT " . $limit;
-			$option.= " OFFSET " . $offset;
-			
-			if($return){
-				return $option;
-			}else{
-				$this->option.= $option;
-			}
-		}
-	}
-	
-	function setgroupby($str) {
-		$this->groupby = "GROUP BY " . $str;
-	}
-	
-	function andwhere($str) {
-		if($this->where != "") {
-			$this->where .= " AND " . $str;
-		} else {
-			$this->where = $str;
-		}
-	}
-	
-	function orwhere($str) {
-		if($this->where != "") {
-			$this->where .= " OR " . $str;
-		} else {
-			$this->where = $str;
-		}
-	}
-		
-	function setwhere($str) {
-		$this->where = $str;
-	}
-	
-	function setorder($str) {
-		$this->order = "ORDER BY " . $str;
-	}
-	
-		
-	function setlimit($limit){
-		if ( is_numeric($limit)){
-			$this->option = " LIMIT " .$limit;
-		}	
-	}
-	
-	function setoffset($offset) {
-		if ( is_numeric($offset)){
-			$this->offset = " OFFSET " .$offset;
-		}	
-	}
-	
-	
-	// INSERTÊ¸¤ÎÀ¸À®¡¦¼Â¹Ô
-	// $table	:¥Æ¡¼¥Ö¥ëÌ¾
-	// $sqlval	:ÎóÌ¾ => ÃÍ¤Î³ÊÇ¼¤µ¤ì¤¿¥Ï¥Ã¥·¥åÇÛÎó
+    /**
+     *  SELECTÊ¸¤ò¹½ÃÛ¤¹¤ë
+     *
+     *  @access public
+     *  @param  string  $col    ¥«¥é¥àÌ¾
+     *  @param  string  $table  ¥Æ¡¼¥Ö¥ëÌ¾
+     *  @param  string  $where  WHERE¶ç
+     *  @return string  SQLÊ¸
+     */
+    function getsql($col, $table, $where="") {
+        if($where != "") {
+            // °ú¿ô¤Î$where¤òÍ¥Àè¤·¤Æ¼Â¹Ô¤¹¤ë¡£
+            $sqlse = "SELECT $col FROM $table WHERE $where " . $this->groupby . " " . $this->order . " " . $this->option;
+        } else {
+            if($this->where != "") {
+                    $sqlse = "SELECT $col FROM $table WHERE $this->where " . $this->groupby . " " . $this->order . " " . $this->option;
+                } else {
+                    $sqlse = "SELECT $col FROM $table " . $this->groupby . " " . $this->order . " " . $this->option;
+            }
+        }
+        return $sqlse;
+    }
+    
+    /**
+     *  WHERE,GROUPBY,ORDERBY°Ê³°¤Î¥ª¥×¥·¥ç¥Ê¥ë¤Ê¶ç¤ò¥»¥Ã¥È¤¹¤ë
+     *
+     *  @access public
+     *  @param  string  $str ¥ª¥×¥·¥ç¥ó¤Ë»ÈÍÑ¤¹¤ëÊ¸»úÎó
+     */
+    function setoption($str) {
+        $this->option = $str;
+    }
+    
+    /**
+     *  LIMIT¶ç¡¢OFFSET¶ç¤ò¥»¥Ã¥È¤¹¤ë
+     *
+     *  @access public
+     *  @param  mixed   $limit  LIMIT¤Î·ï¿ô
+     *  @param  mixed   $offset OFFSET¤Î·ï¿ô
+     *  @param  string  $return À¸À®¤·¤¿LIMIT,OFFSET¶ç¤òreturn¤¹¤ë¤«¤É¤¦¤«
+     *  @return string  À¸À®¤·¤¿LIMIT,OFFSET¶ç
+     */
+    function setlimitoffset($limit, $offset = 0, $return = false) {
+        if (is_numeric($limit) && is_numeric($offset)){
+            
+            $option.= " LIMIT " . $limit;
+            $option.= " OFFSET " . $offset;
+            
+            if($return){
+                return $option;
+            }else{
+                $this->option.= $option;
+            }
+        }
+    }
+
+    /**
+     *  GROUP BY ¶ç¤ò¥»¥Ã¥È¤¹¤ë
+     *
+     *  @access public
+     *  @param  string  $str ¥«¥é¥àÌ¾
+     */
+    function setgroupby($str) {
+        $this->groupby = "GROUP BY " . $str;
+    }
+    
+    /**
+     *  WHERE ¶ç¤ò¥»¥Ã¥È¤¹¤ë(AND)
+     *
+     *  @access  public
+     *  @param   string  $str WHERE ¶ç
+     *  @example $objQuery->andWhere('product_id = ?');
+     */
+    function andwhere($str) {
+        if($this->where != "") {
+            $this->where .= " AND " . $str;
+        } else {
+            $this->where = $str;
+        }
+    }
+    
+    /**
+     *  WHERE ¶ç¤ò¥»¥Ã¥È¤¹¤ë(OR)
+     *
+     *  @access  public
+     *  @param   string  $str WHERE ¶ç
+     *  @example $objQuery->orWhere('product_id = ?');
+     */
+    function orwhere($str) {
+        if($this->where != "") {
+            $this->where .= " OR " . $str;
+        } else {
+            $this->where = $str;
+        }
+    }
+    
+    /**
+     *  WHERE ¶ç¤ò¥»¥Ã¥È¤¹¤ë
+     *
+     *  @access  public
+     *  @param   string  $str WHERE ¶ç
+     *  @example $objQuery->setWhere('product_id = ?');
+     */
+    function setwhere($str) {
+        $this->where = $str;
+    }
+    
+    /**
+     *  ORDER BY ¶ç¤ò¥»¥Ã¥È¤¹¤ë
+     *
+     *  @access  public
+     *  @param   string  $str ¥«¥é¥àÌ¾
+     *  @example $objQuery->setorder("rank DESC");
+     */
+    function setorder($str) {
+        $this->order = "ORDER BY " . $str;
+    }
+    
+    /**
+     *  LIMIT ¶ç¤ò¥»¥Ã¥È¤¹¤ë
+     *
+     *  @access  public
+     *  @param   mixed  $limit LIMIT¤Î·ï¿ô
+     *  @example $objQuery->setlimit(50);
+     */
+    function setlimit($limit){
+        if ( is_numeric($limit)){
+            $this->option = " LIMIT " .$limit;
+        }   
+    }
+    
+    /**
+     *  OFFSET ¶ç¤ò¥»¥Ã¥È¤¹¤ë
+     *
+     *  @access  public
+     *  @param   mixed  $offset OFFSET¤Î·ï¿ô
+     *  @example $objQuery->setOffset(30);
+     */
+    function setoffset($offset) {
+        if ( is_numeric($offset)){
+            $this->offset = " OFFSET " .$offset;
+        }   
+    }
+    
+    /**
+     *  INSERTÊ¸¤ò¼Â¹Ô¤¹¤ë
+     *
+     *  @access  public
+     *  @param   string  $table  ¥Æ¡¼¥Ö¥ëÌ¾
+     *  @param   array   $sqlval (¥«¥é¥àÌ¾ => ÃÍ)¤ÎÏ¢ÁÛÇÛÎó
+     *  
+     *  @return  mixed   $result DB_Error¥ª¥Ö¥¸¥§¥¯¥È(¼ºÇÔ»þ)¤Þ¤¿¤ÏDB_OK(À®¸ù»þ)¤Þ¤¿¤Ïfalse(¥«¥é¥à¤¬¸«¤Ä¤«¤é¤Ê¤¤)
+     */
 	function insert($table, $sqlval) {
 		$strcol = '';
@@ -218,7 +380,13 @@
 	}
 	
-		// INSERTÊ¸¤ÎÀ¸À®¡¦¼Â¹Ô
-	// $table	:¥Æ¡¼¥Ö¥ëÌ¾
-	// $sqlval	:ÎóÌ¾ => ÃÍ¤Î³ÊÇ¼¤µ¤ì¤¿¥Ï¥Ã¥·¥åÇÛÎó
+    /**
+     *  INSERTÊ¸¤ò¼Â¹Ô¤¹¤ë
+     *
+     *  @access  public
+     *  @param   string  $table  ¥Æ¡¼¥Ö¥ëÌ¾
+     *  @param   array   $sqlval (¥«¥é¥àÌ¾ => ÃÍ)¤ÎÏ¢ÁÛÇÛÎó
+     *  
+     *  @return  mixed   $result DB_Error¥ª¥Ö¥¸¥§¥¯¥È(¼ºÇÔ»þ)¤Þ¤¿¤ÏDB_OK(À®¸ù»þ)¤Þ¤¿¤Ïfalse(¥«¥é¥à¤¬¸«¤Ä¤«¤é¤Ê¤¤)
+     */
 	function fast_insert($table, $sqlval) {
 		$strcol = '';
@@ -248,5 +416,5 @@
 		$ret = $this->conn->query($sqlin);
 		
-		return $ret;		
+		return $ret;
 	}
 	
@@ -373,4 +541,5 @@
 	}
 	
+    //»ØÄê¤·¤¿¥«¥é¥à¤Î°ìÈÖºÇ¸å¤Ë¥ì¥³¡¼¥É¤òÁÞÆþ
 	function nextval($table, $colname) {
 		$sql = "";
@@ -379,8 +548,10 @@
 			$seqtable = $table . "_" . $colname . "_seq";
 			$sql = "SELECT NEXTVAL('$seqtable')";
+            $ret = $this->conn->getOne($sql);
 		}else if (DB_TYPE == "mysql") {
-			$sql = "SELECT last_insert_id();";
-		}
-		$ret = $this->conn->getOne($sql);
+            $sql = "SELECT last_insert_id();";
+		    $ret = $this->conn->getOne($sql);
+        }
+		
 		
 		return $ret;
@@ -437,4 +608,3 @@
 	}
 }
-
 ?>
Index: branches/beta/data/class/SC_View.php
===================================================================
--- branches/beta/data/class/SC_View.php	(revision 14392)
+++ branches/beta/data/class/SC_View.php	(revision 14676)
@@ -44,5 +44,5 @@
 		$this->_smarty->register_function("sfPrintEbisTag","sfPrintEbisTag");
 		$this->_smarty->register_function("sfPrintAffTag","sfPrintAffTag");
-        $this->_smarty->default_modifiers = array('script_escape');
+		$this->_smarty->default_modifiers = array('script_escape');
         
 		if(ADMIN_MODE == '1') {		
@@ -96,4 +96,8 @@
 			print("½èÍý»þ´Ö:" . $time . "ÉÃ");
 		}
+        
+        if (DEBUG_MODE === true) {
+            print($_SERVER["SERVER_ADDR"]."-");
+        }
 	}
   	
