Location: PHPKode > scripts > AskPeople-Free PHP survey application > AskPeople_2_2_2/configmgr.php
<?php

session_start();

require_once('includes/config.inc.php');
require_once('includes/functions.inc.php');
require_once('login.inc.php');


$onloadfunc = "showSettingsGroup('access-outputs');";

include('includes/header.php');

switch ($_REQUEST['action']) { 

	case "SaveConfig" :
	
		$defpath = "includes/defaultsettings_ap.php";
		$loaded = loadFile($defpath);
			
		$cpath = "surveys/apconfig.php";

		$parse = preg_match("/\/\/startOfLabels(.*?)\/\/endOfLabels/si",$loaded,$match);		
		$labelschunk = $match[1];

		$parse = preg_match("/\/\/startOfDynamicCode(.*?)\/\/endOfDynamicCode/si",$loaded,$match);		
		$codechunk = $match[1];

		$outputconf .= "<?php\n\n//startOfSettings\n";

		foreach((array)$_POST['config'] as $k => $v) {
			$outputconf .= "\t\$globalsettings[{$k}] = \"".$v."\";\n";
		}		

		$outputconf .= "//endOfSettings\n\n//startOfDynamicCode\n" . $codechunk . "//endOfDynamicCode\n\n//startOfLabels\n" . $labelschunk . "//endOfLabels\n\n";
		$outputconf .= "\n?>";
				
		$saved = saveFile($cpath,$outputconf);
		
		if ($saved) {
			$_SESSION['statusmsg'] = "The settings were saved.";
			header("Location: configmgr.php?action=EditConfig");
		} else {
			$_SESSION['statusmsg'] = "Sorry, the settings could not be saved.";
			header("Location: configmgr.php?action=EditConfig");
		}

		
	  break;
	  
	case "SaveProjectConfig" :
	
		$defpath = "includes/defaultsettings.php";
		$loaded = loadFile($defpath);
		
		include_once($defpath);
		
		$cpath = "surveys/config_" . $_SESSION['admin_sid'] . ".php";
			
		$parse = preg_match("/\/\/startOfLabels(.*?)\/\/endOfLabels/si",$loaded,$match);		
		$labelschunk = $match[1];

		$parse = preg_match("/\/\/startOfDynamicCode(.*?)\/\/endOfDynamicCode/si",$loaded,$match);		
		$codechunk = $match[1];

		$outputconf .= "<?php\n\n//startOfSettings\n";
		//print_r($_POST['config']);
	
		foreach((array)$_POST['config'] as $k => $v) {
			if ($settingslabels[$k]['type'] == "checkbox") { // treat slightly differently
				$outputconf .= "\t\$surveysettings[{$k}] = \""hide@address.com(";",$v)."\";\n";			
			} else {
				$outputconf .= "\t\$surveysettings[{$k}] = \"".$v."\";\n";		
			}			
		}		

		$outputconf .= "//endOfSettings\n\n//startOfDynamicCode\n" . $codechunk . "//endOfDynamicCode\n\n//startOfLabels\n" . $labelschunk . "//endOfLabels\n\n";
		$outputconf .= "\n?>";
				
		$saved = saveFile($cpath,$outputconf);
		
		if ($saved) {
			$_SESSION['statusmsg'] = "The settings were saved.";
			header("Location: configmgr.php?action=EditProjectConfig");
		} else {
			$_SESSION['statusmsg'] = "Sorry, the settings could not be saved.";
			header("Location: configmgr.php?action=EditProjectConfig");
		}
		
	  break;

	case "EditProjectConfig" :
	
		$defpath = "includes/defaultsettings.php";		
		include_once($defpath);

		// then overwrite defaults if project-specific settings exist
		$cpath = "surveys/config_" . $_SESSION['admin_sid'] . ".php";		
		if (!file_exists($cpath)) {
			$defconf = loadFile($defpath);
			$savenewconf = saveFile($cpath,$defconf);
		}
		include($cpath);	
		
		$_SESSION['statusmsg'] = null;

        $directory = (substr(dirname($_SERVER['PHP_SELF']),-1) == "/") ? dirname($_SERVER['PHP_SELF']) : dirname($_SERVER['PHP_SELF']) . "/";
		$surveylink = $protocol . $_SERVER['HTTP_HOST'] . $directory . "survey.php?sid=".$_SESSION['admin_sid'];
				
		$firstloop = "on";
		
		foreach((array)$surveysettings as $sk => $sv) {
	
			if (strlen($settingslabels[$sk]['type'])>0) {
			
				if ($settingslabels[$sk]['type'] != "hidden") {				
					if ($settingslabels[$sk]['group'] != $lastgrouptype) {
						$outputconf .= ($firstloop != "on") ? "</div> <!-- end of settings group -->\n\n" : null;
						$outputconf .= "<div id='{$settingslabels[$sk]['group']}'>\n";
					}
					$outputconf .= "\t<div class='setting {$settingslabels[$sk]['group']}' id='{$sk}'>\n";
				}
						
				switch($settingslabels[$sk]['type']) {
				
					case "boolean" :
						 $outputconf .= "\t\t<p class='settingslabel'>{$settingslabels[$sk]['name']}</p>\n";
						 $outputconf .= "\t\t<p class='settingsdesc'>{$settingslabels[$sk]['description']}</p>\n";
						 $outputconf .= ($sv == "TRUE") ? "\t\t<label><input type='radio' name=\"config[{$sk}]\" value=\"TRUE\" checked='checked'/> On</label>\n" :  "<label><input type='radio' name=\"config[{$sk}]\" value=\"TRUE\" /> On</label>\n";
						 $outputconf .= ($sv == "FALSE") ? "\t\t<label><input type='radio' name=\"config[{$sk}]\" value=\"FALSE\" checked='checked'/> Off</label>\n" :  "<label><input type='radio' name=\"config[{$sk}]\" value=\"FALSE\" /> Off</label>\n";
				
					  break;
					  
					
					case "radio" :
						 $outputconf .= "\t\t<p class='settingslabel'>{$settingslabels[$sk]['name']}</p>\n";
						 $outputconf .= "\t\t<p class='settingsdesc'>{$settingslabels[$sk]['description']}</p>\n";
						 $options = @explode(";",$settingslabels[$sk]['options']);
						 foreach((array)$options as $o) {
							if ($sv == $o) {
								$outputconf .= "\t\t<label><input type='radio' name=\"config[{$sk}]\" value=\"{$o}\" checked='checked' /> {$o}</label>\n";
							} else {
								$outputconf .= "\t\t<label><input type='radio' name=\"config[{$sk}]\" value=\"{$o}\" /> {$o}</label>\n";					 	
							}
						 }
					
					  break;
					  
					case "checkbox" :
						 $outputconf .= "\t\t<p class='settingslabel'>{$settingslabels[$sk]['name']}</p>\n";
						 $outputconf .= "\t\t<p class='settingsdesc'>{$settingslabels[$sk]['description']}</p>\n";
						 $options = @explode(";",$settingslabels[$sk]['options']);
						 $values = @explode(";",$sv);
						 foreach((array)$options as $o) {
							if (strlen($o)>0) {
								if (@in_array($o,$values)) {
									$outputconf .= "\t\t<label><input type='checkbox' name=\"config[{$sk}][{$o}]\" value=\"{$o}\" checked='checked' /> {$o}</label><br />\n";
								} else {
									$outputconf .= "\t\t<label><input type='checkbox' name=\"config[{$sk}][{$o}]\" value=\"{$o}\" /> {$o}</label><br />\n";					 	
								}							
							}
						 }
					
					  break;

					case "hidden" :
						 $outputconf .= "\t\t<input type='hidden' name=\"config[{$sk}]\" value=\"{$sv}\" />\n";
					
					  break;

					case "smallbox" :
						 $outputconf .= "\t\t<p class='settingslabel'>{$settingslabels[$sk]['name']}</p>\n";
						 $outputconf .= "\t\t<p class='settingsdesc'>{$settingslabels[$sk]['description']}</p>\n";
						 $outputconf .= "\t\t<input type='text' name=\"config[{$sk}]\" value=\"".htmlentities($sv)."\" size='70' />\n";
					
					  break;
					  
						  
					default :  // bigbox
						 $outputconf .= "\t\t<p class='settingslabel'>{$settingslabels[$sk]['name']}</p>\n";
						 $outputconf .= "\t\t<p class='settingsdesc'>{$settingslabels[$sk]['description']}</p>\n";
						 $outputconf .= "\t\t<textarea name=\"config[{$sk}]\" rows='3' cols='80'>".htmlentities($sv)."</textarea>\n";
					
					  break;
				
				}
	
				if ($settingslabels[$sk]['type'] != "hidden") {
					$outputconf .= "\t</div>\n";
				}
				
				$lastgrouptype = $settingslabels[$sk]['group'];
				
				$firstloop = "off";
			}
		}
		
		$outputconf .= "</div> <!-- end of final settings group -->\n\n";

		$conf = "
			<p id='surveylink'><img src=\"images/icons/web_16x16.gif\" width=\"16\" height=\"16\" class='icon' alt=\"Link to survey\" border=\"0\" />The link to this survey is: <a href='{$surveylink}'>{$surveylink}</a></p>
			<div id='editform' style='width:99%'>
				<form action='configmgr.php' method='post' class='clearbox'>
				<ul id='settings-tabs'>
				  <li id='tab-access-outputs'><a onclick=\"showSettingsGroup('access-outputs'); return false;\" href='#access-outputs'>Access &amp; outputs</a></li>
				  <li id='tab-display'><a onclick=\"showSettingsGroup('display'); return false;\" href='#display'>Questionnaire display</a></li>
				  <li id='tab-labels-messages'><a onclick=\"showSettingsGroup('labels-messages'); return false;\" href='#labels-messages'>Labels &amp; messages</a></li>
				</ul>
				
				{$outputconf}
				<input type='hidden' name='action' value='SaveProjectConfig' />
				<p style='text-align:center;'><input type=\"submit\" value='Save changes' /> or <a href='/projmgr.php'>cancel</a></p>
				</form>
			</div>
		";

		echo ($conf);

	  break;

	default : // same as EditConfig
	
		$defpath_ap = "includes/defaultsettings_ap.php";		
		@include_once($defpath_ap);

		// then overwrite defaults where user-defined global settings exist
		$cpath = "surveys/apconfig.php";		
		if (!file_exists($cpath)) {
			$defconf = loadFile($defpath_ap);
			$savenewconf = saveFile($cpath,$defconf);
		}
		include($cpath);	
				
		$title = "AskPeople settings";		
		$_SESSION['statusmsg'] = null;

		foreach((array)$globalsettings as $sk => $sv) {
	
			if ($settingslabels[$sk]['type'] != "hidden") {				
				$outputconf .= "\t<div class='setting' id='{$sk}'>\n";
			}
	
			switch($settingslabels[$sk]['type']) {
			
				case "boolean" :
					 $outputconf .= "<p class='settingslabel'>{$settingslabels[$sk]['name']}</p>\n";
					 $outputconf .= "<p class='settingsdesc'>{$settingslabels[$sk]['description']}</p>\n";
					 $outputconf .= ($sv == "TRUE") ? "<label><input type='radio' name=\"config[{$sk}]\" value=\"TRUE\" checked='checked'/> On</label>\n" :  "<label><input type='radio' name=\"config[{$sk}]\" value=\"TRUE\" /> On</label>\n";
					 $outputconf .= ($sv == "FALSE") ? "<label><input type='radio' name=\"config[{$sk}]\" value=\"FALSE\" checked='checked'/> Off</label>\n" :  "<label><input type='radio' name=\"config[{$sk}]\" value=\"FALSE\" /> Off</label>\n";
			
				  break;
				  
				
			    case "radio" :
					 $outputconf .= "<p class='settingslabel'>{$settingslabels[$sk]['name']}</p>\n";
					 $outputconf .= "<p class='settingsdesc'>{$settingslabels[$sk]['description']}</p>\n";
					 $options = @explode(";",$settingslabels[$sk]['options']);
					 foreach((array)$options as $o) {
					 	if ($sv == $o) {
					 		$outputconf .= "<label><input type='radio' name=\"config[{$sk}]\" value=\"{$o}\" checked='checked' /> {$o}</label>\n";
					 	} else {
					 		$outputconf .= "<label><input type='radio' name=\"config[{$sk}]\" value=\"{$o}\" /> {$o}</label>\n";					 	
					 	}
					 }
			    
			      break;
			      
				case "checkbox" :
					 $outputconf .= "\t\t<p class='settingslabel'>{$settingslabels[$sk]['name']}</p>\n";
					 $outputconf .= "\t\t<p class='settingsdesc'>{$settingslabels[$sk]['description']}</p>\n";
					 $options = @explode(";",$settingslabels[$sk]['options']);
					 $values = @explode(";",$sv);
					 foreach((array)$options as $o) {
						if (strlen($o)>0) {
							if (@in_array($o,$values)) {
								$outputconf .= "\t\t<label><input type='checkbox' name=\"config[{$sk}][{$o}]\" value=\"{$o}\" checked='checked' /> {$o}</label><br />\n";
							} else {
								$outputconf .= "\t\t<label><input type='checkbox' name=\"config[{$sk}][{$o}]\" value=\"{$o}\" /> {$o}</label><br />\n";					 	
							}							
						}
					 }
				
				  break;

				case "hidden" :
					 $outputconf .= "<input type='hidden' name=\"config['{$sk}']\" value=\"{$sv}\" />\n";
				
				  break;

			    case "smallbox" :
					 $outputconf .= "<p class='settingslabel'>{$settingslabels[$sk]['name']}</p>\n";
					 $outputconf .= "<p class='settingsdesc'>{$settingslabels[$sk]['description']}</p>\n";
				 	 $outputconf .= "<input type='text' name=\"config[{$sk}]\" value=\"".htmlentities($sv)."\" size='70' />\n";
			    
			      break;
			      
			    default : //bigbox
					 $outputconf .= "<p class='settingslabel'>{$settingslabels[$sk]['name']}</p>\n";
					 $outputconf .= "<p class='settingsdesc'>{$settingslabels[$sk]['description']}</p>\n";
				 	 $outputconf .= "<textarea name=\"config[{$sk}]\" rows='3' cols='80'>".htmlentities($sv)."</textarea>\n";
			    
			      break;
			
			}

			if ($settingslabels[$sk]['type'] != "hidden") {
				$outputconf .= "\t</div>\n";
			}
		}
		
		$conf = "
			<div id='editform' style='width:99%'>
				<form action='configmgr.php' method='post' class='clearbox'>
				<h2>{$title}</h2>
				<br />
				<div id='site-settings'>
				{$outputconf}
				</div>
				<input type='hidden' name='action' value='SaveConfig' />
				<p style='text-align:center;'><input type=\"submit\" value='Save changes' /> or <a href='projmgr.php'>cancel</a></p>
				</form>
			</div>
		";

		echo ($conf);


    	break;
}

include('includes/footer.php');

?>
Return current item: AskPeople-Free PHP survey application