<?
IncludeModuleLangFile(__FILE__);
global $MESS;
include(GetLangFileName($GLOBALS["DOCUMENT_ROOT"]."/bitrix/modules/main/lang/",     "/options.php"));
CModule::IncludeModule("iblock");

if(!$USER->CanDoOperation('view_other_settings') && !$USER->CanDoOperation('edit_other_settings'))
	$APPLICATION->AuthForm(GetMessage("ACCESS_DENIED"));

$strWarning = "";

$franciseOpt=Array(				
				"company_city" => GetMessage("DEMO_SITE_COMPANY_CITY"),
				"company_address" => GetMessage("DEMO_SITE_COMPANY_ADDRESS"),
				"company_phone_code" => GetMessage("DEMO_SITE_COMPANY_PHONE_CODE"),
				"company_phone" => GetMessage("DEMO_SITE_COMPANY_PHONE"),
				"company_icq" => GetMessage("DEMO_SITE_COMPANY_ICQ"),
				"company_skype" => GetMessage("DEMO_SITE_COMPANY_SKYPE"),				
				"company_info" => GetMessage("DEMO_SITE_COMPANY_INFO"),
				"1c_news_iblock_id" => GetMessage("DEMO_SITE_1c_news_iblock_id"),
				"1c_news_section_id" => GetMessage("DEMO_SITE_1c_news_section_id"),	
				"1c_news_url" => GetMessage("DEMO_SITE_1c_news_url"),				
			);
			
if ($REQUEST_METHOD=="POST" && strlen($Update) > 0 && $USER->CanDoOperation('edit_other_settings')) {
	  foreach($franciseOpt as $name => $caption)
	  {
	  	COption::SetOptionString("franchise", $name,  $_REQUEST[$name]);
	  }
}

if (strlen($strWarning) > 0) {
	CAdminMessage::ShowMessage($strWarning);
}

$aTabs = array(
	array("DIV" => "edit1", "TAB" => GetMessage("FRANCHISE_TAB_SET"), "ICON" => "gossite_settings", "TITLE" => GetMessage("FRANCHISE_TAB_SET_ALT")),	
);
$tabControl = new CAdminTabControl("tabControl", $aTabs);

$tabControl->Begin();

?><form method="POST" enctype="multipart/form-data" action="<?echo $APPLICATION->GetCurPage()?>?mid=<?=htmlspecialchars($mid)?>&lang=<?=LANGUAGE_ID?>">

<? $tabControl->BeginNextTab(); ?>

	<?foreach($franciseOpt as $name => $caption):?>
		<tr>
			<td valign="top" width="50%"><?=$caption?>:</td>
			<td valign="top" width="50%">
				<?if($name=='1c_news_iblock_id'):?>
					<?echo GetIBlockDropDownListEx(COption::GetOptionString("franchise", $name, ""), '1c_news_iblock_type_id', $name, false, '', 'this.form.submit();');?>					
				<?elseif($name=='1c_news_section_id'):
					$curIb=COption::GetOptionString("franchise", "1c_news_iblock_id", "");
					if($_REQUEST['1c_news_iblock_id'])
						$curIb=$_REQUEST['1c_news_iblock_id'];					
					$db_list = CIBlockSection::GetList(Array("NAME"=>"ASC"), $arFilter=array('IBLOCK_ID'=>$curIb), false);
					 $arrSect=array();?>
					 <select size="1" id="1c_news_section_id" name="1c_news_section_id" class="typeselect">
					 	<option value=""><?=GetMessage('NOT_SELECTED')?></option>
					 <?$curSect=COption::GetOptionString("franchise", $name, "");
					 while($ar_result = $db_list->GetNext())
					 {
					 	if($curSect==$ar_result['ID'])
					 		$selected='selected';
					 	else
					 		$selected='';?>					 	
					 	<option value="<?=$ar_result['ID']?>" <?=$selected?>><?=$ar_result['NAME']?></option>					 	
					 <?}?>	
					</select>				
				<?else:?>
					<input type="text" size="50" name="<?=$name?>" value="<?echo COption::GetOptionString("franchise", $name, "");?>" />
				<?endif?>
			</td>
		</tr>
	
	<?endforeach?>

<?$tabControl->Buttons();?>
<script language="JavaScript">
function RestoreDefaults()
{
	if (confirm('<?echo AddSlashes(GetMessage("MAIN_HINT_RESTORE_DEFAULTS_WARNING"))?>'))
		window.location = "<?echo $APPLICATION->GetCurPage()?>?RestoreDefaults=Y&lang=<?echo LANG?>&mid=<?echo urlencode($mid)?>";
}
</script>

<input type="submit" <?if (!$USER->CanDoOperation('edit_other_settings')) echo "disabled" ?> name="Update" value="<?echo GetMessage("MAIN_SAVE")?>">
<input type="hidden" name="Update" value="Y">
<input type="reset" name="reset" value="<?echo GetMessage("MAIN_RESET")?>">
<input type="button" <?if (!$USER->CanDoOperation('edit_other_settings')) echo "disabled" ?> title="<?echo GetMessage("MAIN_HINT_RESTORE_DEFAULTS")?>" OnClick="RestoreDefaults();" value="<?echo GetMessage("MAIN_RESTORE_DEFAULTS")?>">
<?$tabControl->End();?>
</form>