phorum\index.ppc :: ppC++ web compiler
   <?// including header:
#ppcinclude "include/header.ppc"
?>
<? int sect_num = ppc.int(ppc.read_file("dat/sect_num"));	?>


<center>
<?
if(ppc.op=="addsector"){if(isadmin){
	if(ppc.addsector=="yes"){		
		// adding a sector:
		if(ppc.capt==""){
		?><script>alert('Cannot add empty sector...');
			location.replace('<?=ppc.SCRIPT?>')</script><?
			exit(0);}
		ppc.save_file("dat/sect_"+ppc.string(sect_num), ppc.capt  );
		ppc.save_file("dat/sect_"+ppc.string(sect_num)+"_desc", ppc.desc  );
		ppc.save_file("dat/sect_"+ppc.string(sect_num)+"_modr", ppc.modr  );		
		sect_num++;
		ppc.save_file("dat/sect_num", ppc.string(sect_num) );
		?><script>location.replace('<?=ppc.SCRIPT?>');
					alert('Sector is added')</script><?
	}else{//showing add sector form
	?><form method=post action='<?=ppc.SCRIPT?>?op=addsector&addsector=yes'>
	<b>ADD NEW SECTOR</b>
	<?oTable1(55)?>
		Sector caption</td><td><input name=capt size=16 maxsize=32></td></tr>
		<tr><td>Description</td><td><input name=desc size=32 maxsize=64></td></tr>
		<tr><td>Moderator name</td><td><input name=modr size=16 maxsize=32></td></tr>
		<tr><td>&nbsp;</td><td>
			<input type=submit value='add'>
	<?cTable()?>
	</form><?			
	}
}}
else if(ppc.op=="editsector"){if(isadmin){
	if(ppc.editsector=="yes"){		
		// saving a sector:
		if(ppc.capt==""){
		?><script>alert('Cannot save empty sector...');
			location.replace('<?=ppc.SCRIPT?>')</script><?
			exit(0);}
		ppc.save_file("dat/sect_"+ppc.sector, ppc.capt  );
		ppc.save_file("dat/sect_"+ppc.sector+"_desc", ppc.desc  );
		ppc.save_file("dat/sect_"+ppc.sector+"_modr", ppc.modr  );		
		?><script>location.replace('<?=ppc.SCRIPT?>');
					alert('Sector is saved')</script><?
	}else{//showing add sector form
	?><form method=post action='<?=ppc.SCRIPT?>?op=editsector&editsector=yes&sector=<?=ppc.sector?>'>
	<b>edit sector <b>"<?=ppc.read_file("dat/sect_"+ppc.sector)?>"</b></b>
	<?oTable1(55)?>
		Sector caption</td><td><input name=capt size=16 maxsize=32 
			value='<?=ppc.read_file("dat/sect_"+ppc.sector)?>'></td></tr>
		<tr><td>Description</td><td><input name=desc size=32 maxsize=64
			value='<?=ppc.read_file("dat/sect_"+ppc.sector+"_desc")?>'></td></tr>
		<tr><td>Moderator name</td><td><input name=modr size=16 maxsize=32
			value='<?=ppc.read_file("dat/sect_"+ppc.sector+"_modr")?>'></td></tr>
		<tr><td>&nbsp;</td><td>
			<input type=submit value='change'>
	<?cTable()?>
	</form><?			
	}
}}
else if(ppc.op=="deletesector"){if(isadmin){
	const char *to_c_str(string a){ static string b=a; return b.c_str(); }
	int csect = ppc.int(ppc.sector);
	// removing all sector's files:
	remove(to_c_str("dat/sect_"+ppc.sector));
	remove(to_c_str("dat/sect_"+ppc.sector+"_desc"));
	remove(to_c_str("dat/sect_"+ppc.sector+"_modr"));
		?><script>location.replace('<?=ppc.SCRIPT?>');
					alert('Sector is deleted')</script><?
}}
else if(ppc.op=="fsector"){
#ppcinclude "include/fsector.ppc"
}
else if(ppc.op=="reply"){
	// number of answers is here: 
	int answ = ppc.int(ppc.read_file("dat/top_"+ppc.s+"_"+ppc.t+"_anum" ));
	ppc.save_file("dat/top_"+ppc.s+"_"+ppc.t+"_"+ppc.string(answ)+"_auth",
							ppc.author);
	ppc.save_file("dat/top_"+ppc.s+"_"+ppc.t+"_"+ppc.string(answ)+"_cont",
							ppc.cont);
	answ++;							
	ppc.save_file("dat/top_"+ppc.s+"_"+ppc.t+"_anum",ppc.string(answ) );
	cookie.set("ppcsimplephorumuname="+ppc.author);
	xredir("Your post is published!", "op=ft&sop=show&s="+ppc.s+"&t="+ppc.t);
}
else if(ppc.op=="ft"){
#ppcinclude "include/ftopic.ppc"
}
else{
?><div align=left><h2>Main sectors of <?=title?></h2></div><?
	if(isadmin){
		?><a  class=clred href='<?=ppc.SCRIPT?>?op=addsector'>add sector</a>
	<?}
// I must fetch a sectors here:
/*
    number of sectors is in "dat/sect_num"
    every sector caption filename is "dat/sect_$i"
    every sector description filename is "dat/sect_$i_desc"
    every sector moderator-name filename is "dat/sect_$i_modr"
*/
 string sectc;t1=false;
for(int i=0;i<sect_num;++i){
 if( (sectc = ppc.read_file(string("dat/sect_")+ppc.string(i)) )!="" ){
	if(t1=!t1)oTable1a();
	else      oTable2a();
	oTable3a()?>
	<?if(isadmin){
		oTable1()
		?><center>
		<a  class=clred href='<?=ppc.SCRIPT?>?sector=<?=i?>&op=editsector'>edit sector</a>
		&nbsp;&nbsp;&nbsp;
		<script language=JavaScript>
		function areyousure(iii){
			if(confirm('Sure?') ){
				location.replace('<?=ppc.SCRIPT?>?sector='+iii+'&op=deletesector');
			}
		}
		</script>
		<a  class=clred href='javascript:areyousure(<?=i?>)'>delete sector</a>
		</center><?
		cTable();		
	}?>	
	<a class=sectHead href='<?=ppc.SCRIPT?>?op=fsector&s=<?=i?>'><?=sectc?></a><?cTable();
	sectc = ppc.read_file(string("dat/sect_")+ppc.string(i)+string("_desc"));
	if(sectc!=""){oTable4a()?>
		<a class=sectSmall href='<?=ppc.SCRIPT?>?op=fsector&s=<?=i?>'>
		<?=sectc?></a><?cTable();}
	sectc = ppc.read_file(string("dat/sect_")+ppc.string(i)+string("_modr"));
   if(sectc!=""){?><div align=right>Moderator: <i><?=sectc?></i></div><?}
	cTable();
 }
}
if(!sect_num){
	oTable1()?><h3>No sectors are published in this phorum</h3>
	<?if(isadmin){
		?><a href='<?=ppc.SCRIPT?>?op=addsector'>add sector</a>
		<?}else{?>
			Please go to <a href='<?=ppc.SCRIPT?>?op=admin'>administrator section</a> to add and manage sectors.
		<?}?>	
	<?cTable();
}

}
?>
</center>


<?// including footer:
#ppcinclude "include/footer.ppc"
?>
                       






General Public License
2003 ppC++ team