<?php
	require("__include-common.php");
	require("../account/__logincheck.php");
	require("img-view-include.php");
	set_time_limit(0);		//実行時間制御なし　max_execution_time
	if (photo_IMAGEMAGIC <> 'YES') {
		exit;
	}
	if ($_SESSION['システム管理者'] <> 'YES' and photo_IMAGEMAGIC_ALLUSER <> 'YES') {
		exit;
	}
	if (($path = my_GET('path')) == '') exit;
	if (($src = my_GET('src')) == '') exit;
	if (($cnv = my_GET('cnv')) == '') exit;
	if (($dir = my_GET('dir')) == '') exit;
	if (($opt = my_GET('opt')) == '') exit;
	if (defined("photo_LIMITED_IMAGES_FOLDER") and photo_LIMITED_IMAGES_FOLDER <> '') {
		if ($_SESSION['システム管理者'] <> 'YES' or photo_LIMITED_ADMIN_NOLIMIT <> 'YES') {
			$len = strlen(photo_LIMITED_IMAGES_FOLDER);
			if (substr($path, 0, $len) <> photo_LIMITED_IMAGES_FOLDER) {
				header("Location: index.php");
			}
		}
	}
	$opt = str_replace('_',' ',$opt);
	if ($_SESSION['システム管理者'] <> 'YES') {
		// システム管理者以外は、テーブルm_convert_optに登録されているオプション以外は処理させない(安全のため)
		$con = my_mysql_connect(_DB_SCHEMA);
		$sql = 'select * from m_convert_opt where c_delete = 0 and id_opt = '.my_GET('opno');
		$rs = my_mysql_query($sql);
		if (!($rec = mysql_fetch_array($rs))) {
			exit;
		};
		if ($rec['c_option'] <> $opt) {
			exit;
		}
		$con = mysql_close($con);
	}
	$src_path = $path.'/'.$src;
	$cnv_dir = $path.'/'.$dir;
	if (!@opendir(myfile_ENCODE($cnv_dir))) {
		@mkdir(myfile_ENCODE($cnv_dir));
	}
	$cnv_path = $cnv_dir.'/'.$cnv;
	$src_SJIS = myfile_ENCODE($src_path);
	$cnv_SJIS = myfile_ENCODE($cnv_path);
	exec('convert '.$opt.' "'.$src_SJIS.'" "'.$cnv_SJIS.'"');
	img_view($cnv_path, '', my_GET('ov'));
?>
