<?php
/*
 * content/variable/Save.class.php
 * 
 * CopyRight(C) 2010 Shopformer Development Team. All Right Reserved
 * URL: http://sourceforge.jp/projects/shopformer/
 * 
 * 
 * Mail: m_nakashima@users.sourceforge.jp
 * Auther: Masanori Nakashima
 * Last Update: 2010-07-22
 */
require_once( dirname(dirname(dirname(__FILE__)))
	.DIRECTORY_SEPARATOR.'system'
	.DIRECTORY_SEPARATOR.'login'
	.DIRECTORY_SEPARATOR.'ModuleBase.class.php');
require_once( dirname(dirname(__FILE__))
	.DIRECTORY_SEPARATOR.'Variable.class.php');
class content_variable_Save extends system_login_ModuleBase {
	function content_variable_Save() {
	}
	function execute( & $request ) {
		$variableObject			= new content_Variable($request);
		if( !$request->isError() ) {
			$variableKeyArray		= $request->getParam('variable_key','post','array');
			$variableLabelArray		= $request->getParam('variable_label','post','array');
			$variableValueArray		= $request->getParam('variable_value','post','array');
			if( is_array($variableKeyArray) ) {
				foreach( $variableKeyArray as $num => $key ) {
					$vLabel	= '';
					$vValue	= '';
					if( is_array($variableLabelArray) && isset($variableLabelArray[$num]) ) {
						$vLabel	= str_replace("\r","",$variableLabelArray[$num]);
						$vLabel	= str_replace("\n","",$vLabel);
					}
					if( is_array($variableValueArray) && isset($variableValueArray[$num]) ) {
						$vValue	= str_replace("\r\n","\n",$variableValueArray[$num]);
						$vValue	= str_replace("\r","\n",$vValue);
					}
					$variableObject->setValue( $request, $key, $vValue );
					$variableObject->setLabel( $request, $key, $vLabel );
				}
			}
			$variableObject->_save( $request );
			$request->setAttribute('content.variable.VariableObject',$variableObject );
			// 他パッケージの追加ビルド内容を実行
			if( is_dir(DIR_PATH_LIB) ) {
				$dh	= @opendir( DIR_PATH_LIB );
				if( $dh ) {
					while (($fileName = readdir($dh)) !== false) {
						if( preg_match('/^\\./',$fileName) == 0 ) {
							$extPath	= DIR_PATH_LIB.DIRECTORY_SEPARATOR.$fileName
								.DIRECTORY_SEPARATOR.'SynchronizeVariable.class.php';
							if( file_exists($extPath) ) {
								require_once( $extPath );
								$className			= $fileName.'_SynchronizeVariable';
								$synchronizeObject	= new $className;
								if( is_a($synchronizeObject,'content_SynchronizeVariable') ) {
									// 適用を実行
									$synchronizeObject->apply( $request );
								}
							}
						}
					}
					@closedir($dh);
				}
			}

		}
	}
}
?>