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

session_start();

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

include('includes/header.php');

if (!@in_array($_SESSION['admin_sid'],$_SESSION['allowedaccess'])) { // user doesn't have access to this survey
	die ("<div class='clearbox'><h2>Access denied</h2><p>Sorry, this project has not yet been shared with you. Please contact the project owner to be granted access, or <a href='index.php'>return to My Projects</a> and check whether the project is listed there.</p><br /></div>");
}

//print_r($_REQUEST);

switch ($_REQUEST['action']) { // questionnaire to be saved

	case "SaveConfig" :
	
		$cpath = "surveys/config_" . $_SESSION['admin_sid'] . ".php";
		$saved = saveFile($cpath,$_POST['confightml']);		

		if ($saved) {
			$_SESSION['statusmsg'] = "The project settings were saved.";
			header("Location: projmgr.php?action=EditConfig");
		} else {
			$_SESSION['statusmsg'] = "Sorry, the project settings could not be saved.";
			header("Location: projmgr.php?action=EditConfig");
		}

	  break;

	case "EditConfig" :
	
		$cpath = "surveys/config_" . $_SESSION['admin_sid'] . ".php";
		$loaded = loadFile($cpath);		

		$title = "Project settings:";
		
		$_SESSION['statusmsg'] = null;
		
		$outputform = "
			<div id='editform' style='width:99%'>
				<form action='projmgr.php' method='post' class='clearbox'>
				<h2>{$title} {$_SESSION['admin_stitle']}</h2>
				<textarea cols='80' rows='25' name='confightml'>{$loaded}</textarea>
				<input type='hidden' name='action' value='SaveConfig' />
				<p style='text-align:center;'><input type=\"submit\" value='Save changes' /></p></form>
			</div>
		";

	  break;


	case "BackupProject" :
	
		$saved = backupProject($_SESSION['admin_sid'],$_SESSION['admin_stitle'],$cookieinfo['email']);		

		if ($saved) {
			$_SESSION['statusmsg'] = "Backup project files were emailed to ".$cookieinfo['email'];
			header("Location: projmgr.php");
		} else {
			$_SESSION['statusmsg'] = "Sorry, the project files could not be backed up by email.";
			header("Location: projmgr.php");
		}	
	
	  break;

	case "DeleteProject" :

		$deleteq = "surveys/quest_" . $_SESSION['admin_sid'] . ".xml";
		$deletedat = "surveys/data_" . $_SESSION['admin_sid'] . ".dat";
		$deleteconf = "surveys/config_" . $_SESSION['admin_sid'] . ".php";

		if (file_exists($deleteq)) {
			$temp = file_get_contents($deleteq);
			saveFile("trash/".$deleteq,$temp); // move file to the /trash dir		
			$deleted = unlink($deleteq);

			if ($deleted) {
				$_SESSION['statusmsg'] = "Deleted: project questionnaire";
			} else {
				$_SESSION['statusmsg'] = "Project questionnaire could not be deleted";
			}
		}

		if (file_exists($deletedat)) {
			$temp = file_get_contents($deletedat);
			saveFile("trash/".$deletedat,$temp); // move file to the /trash dir		
			$deleted2 = unlink($deletedat);

			if ($deleted2) {
				$_SESSION['statusmsg'] .= " and response datafile";
			} else {
				$_SESSION['statusmsg'] .= "; response datafile could not be deleted";
			}
		}

		if (file_exists($deleteconf)) {
			$temp = file_get_contents($deleteconf);
			saveFile("trash/".$deleteconf,$temp); // move file to the /trash dir		
			$deleted3 = unlink($deleteconf);

			if ($deleted3) {
				$_SESSION['statusmsg'] .= " and project settings";
			} else {
				$_SESSION['statusmsg'] .= "; project settings could not be deleted";
			}
		}

		header("Location: index.php");

	  break;
	

	default :
        $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'];
	
		$_SESSION['statusmsg'] = null;
		
		$cpath = "surveys/config_" . $_SESSION['admin_sid'] . ".php";		
		@include($cpath);
		
 		if ($surveysettings['surveyStatus'] == "Open") {
 			$statusbox .= "<li class='status open'><img src='images/icons/start.gif' class='icon' alt='Project status: open' width='16' height='16' border='0' /> This project is currently <strong>open</strong> to new responses. <span><a href='configmgr.php?action=EditProjectConfig#surveyStatus'>Close</a> the survey?</span></li>\n";
 		} else {
 			$statusbox .= "<li class='status closed'><img src='images/icons/stop.gif' class='icon' alt='Project status: closed' width='16' height='16' border='0' /> This project is currently <strong>closed</strong> to new responses. <span><a href='configmgr.php?action=EditProjectConfig#surveyStatus'>Open</a> the survey?</span></li>\n"; 		
 		}

		// quick count of topline results
		$datafile = "surveys/data_" . $_SESSION['admin_sid'] . ".dat";
		$rawdata = loadFile($datafile);
		if ($rawdata) {
			$rawdata_array = @explode("\n",$rawdata);
			$responsecount = count($rawdata_array)-1;
		} else {
			$responsecount = "0";
		}

 		$statusbox .= "<li class='status responsescount'><img src='images/icons/report_user.gif' class='icon' alt='Project status: number of responses' width='16' height='16' border='0' /> <strong>{$responsecount} responses</strong> have been received so far. <span>See results <a href='statreport.php?qid=all&show=both'>overview</a> or <a href='respondentreport.php'>one-by-one</a></span></li>\n";
		
 		if (strlen($surveysettings['emailResults'])>0) {
 			$statusbox .= "<li class='status emailresponses'><img src='images/icons/email.gif' class='icon' alt='Project status: email notifications' width='16' height='16' border='0' /> New responses are automatically emailed to <strong>{$surveysettings['emailResults']}</strong>. <span><a href='configmgr.php?action=EditProjectConfig#emailResults'>Change</a> the address for email notifications?</span></li>\n";
 		} else {
 			$statusbox .= "<li class='status emailresponses'><img src='images/icons/email.gif' class='icon' alt='Project status: email notifications' width='16' height='16' border='0' /> Responses are being stored in the database. <span>Would you like to <a href='configmgr.php?action=EditProjectConfig#emailResults'>receive email notifications</a> of new responses?</span></li>\n"; 		
 		}

		$sharedwith = @explode(";",$surveysettings['surveyGroup']);
		foreach((array)$sharedwith as $u) {
			@eregi("(.*)\(ID:",$u,$match);
			if (strlen(trim($match[1]))>0) {
				$userlist[] = trim($match[1]);
			}
		}
		
		//print_r($userlist);
		
 		if (count($userlist)>0) {
 			$statusbox .= "<li class='status shared-on'><img src='images/icons/database_shared_16x16.gif' class='icon' alt='Sharing status: shared' width='16' height='16' border='0' /> This project is currently <strong>shared with "hide@address.com(", ",$userlist)."</strong>. <span><a href='configmgr.php?action=EditProjectConfig#surveyGroup'>Change</a> sharing setup?</span></li>\n";
 		} else {
 			$statusbox .= "<li class='status shared-off'><img src='images/icons/database_shared_16x16.gif' class='icon' alt='Sharing status: not shared' width='16' height='16' border='0' /> This project is <strong>not currently shared</strong> with other AskPeople users. <span><a href='configmgr.php?action=EditProjectConfig#surveyGroup'>Share</a> it now?</span></li>\n"; 		
 		}
 		
 		
 		$rssfile = "rss/rss_".$_SESSION['admin_sid'].".xml";
 		//if (!file_exists($rssfile)) { // need to include rssreport.php to generate new feed
			if ($surveysettings['makeRSS'] == "TRUE") {
				$_REQUEST['file'] = "TRUE";
				include_once("rssreport.php");
			} 		
 		//}
 		
 		$outputform .= "			
			<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 class='statusbox'>
			  <ul>
				{$statusbox}
			  </ul>
			</div>
			
			<div id=\"qrelinks\" class=\"adminlinks\" style=\"width:49%; float:left;\">
				<div class=\"clearbox\">
					<h2>Questionnaire</h2>
					<ul>
						<li><a href='survey.php?sid={$_SESSION['admin_sid']}'><img src='images/icons/preview_16x16.gif' class='icon' alt='View questionnaire' width='16' height='16' border='0' />View questionnaire</a></li>
						<li><a href='qeditor.php?action=EditQuestionnaire'><img src='images/icons/edit_16x16.gif' class='icon' alt='Edit questionnaire' width='16' height='16' border='0' />Edit questionnaire</a></li>
						<li><a href='qeditor.php?action=EditXML'><img src='images/icons/script_(edit)_16x16.gif' class='icon' alt='Edit project' width='16' height='16' border='0' />Edit raw script</a></li>
						<li><a href='qeditor.php?action=ExportQuestionnaire'><img src='images/icons/file_(export)_16x16.gif' class='icon' alt='Export plain text version' width='16' height='16' border='0' />Export plain text version</a></li>
					</ul>
				</div>
				<div class=\"clearbox\">
					<h2>Data</h2>
					<ul>
						<li><a href='respondentreport.php?action=DownloadData'><img src='images/icons/database_export_16x16.gif' class='icon' alt='Download data' width='16' height='16' border='0' />Download data</a></li>
						<li><a href='respondentreport.php?action=EditData'><img src='images/icons/database_(edit)_16x16.gif' class='icon' alt=View and edit data' width='16' height='16' border='0' />View &amp; edit raw data</a></li>
					</ul>
				</div>
			</div>
			
			<div class=\"adminlinks\" style=\"width:49%; float:right;\">
				<div class=\"clearbox\">
					<h2>Project options</h2>
					<ul>
						<li><a href='configmgr.php?action=EditProjectConfig'><img src='images/icons/settings1_16x16.gif' class='icon' alt='Settings for this project' width='16' height='16' border='0' />Manage project settings</a></li>
						<li><a onclick='return confirmSubmit(\"Are you sure? Deleted questionnaires and response datafiles are moved to the trash directory and can no longer be accessed.\");' href='projmgr.php?action=DeleteProject'><img src='images/icons/trash_16x16.gif' class='icon' alt='Delete project' width='16' height='16' border='0' />Delete this project</a></li>
						<li><a href='projmgr.php?action=BackupProject'><img src='images/icons/backup_16x16.gif' class='icon' alt='Backup this project by email' width='16' height='16' border='0' />Backup project by email</a></li>
						<li><a href='index.php?action=Duplicate'><img src='images/icons/copy_16x16.gif' class='icon' alt='Duplicate questionnaire' width='16' height='16' border='0' />Duplicate questionnaire</a></li>
						<li><a href='launch.php?action=ShowCode'><img src='images/icons/anchor_16x16.gif' class='icon' alt='Launch survey' width='16' height='16' border='0' />Help with launching your survey</a></li>
					</ul>
				</div>
				<div class=\"clearbox\">
					<h2>Results</h2>
					<ul>
						<li><a href='statreport.php?qid=all&show=both'><img src='images/icons/report2_16x16.gif' class='icon' alt='View topline results' width='16' height='16' border='0' />View topline results</a></li>
						<li><a href='respondentreport.php'><img src='images/icons/user2_16x16.gif' class='icon' alt='View individual responses' width='16' height='16' border='0' />View individual responses</a></li>
						<li><a href='{$rssfile}'><img src='images/icons/rss_16x16.gif' class='icon' alt='View RSS feed' width='16' height='16' border='0' />Monitor responses by RSS</a></li>
					</ul>
				</div>

			</div>	
		";
	
	
	break;

}

// output the HTML
echo ($outputform);

include('includes/footer.php');

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