Open Source Web Development Tutorials - Dev Shed
プロジェクト管理アプリケーションの仕上げ
(2009/01/08公開)
自作!プロジェクト管理アプリケーション:データベースとログインページ
プロジェクト管理アプリケーションのHTMLを解析
プロジェクト管理アプリケーションに変更を加える
プロジェクト管理アプリケーションのタスクを追加する
プロジェクト管理アプリケーションのタスク閲覧/編集
プロジェクト管理アプリケーションのファイル処理
プロジェクト管理アプリケーションの仕上げ
第7回では、プロジェクト管理アプリケーションの仕上げとして、残る3つのスクリプトを取り上げます。「プロジェクトの要員の氏名を表示する」および「プロジェクトに要員を追加する」ほか、「プロジェクトから要員を削除する」ことができます。今回はいよいよ全7回の連載の最終回です。
add_staffスクリプト
プロジェクト管理者には、add_staffページで、プロジェクトに要員を追加するオプションを提供します。すなわち、スクリプトによってユーザーにフォームを提示し、ユーザーはフォーム中のテキストフィールドに要員の氏名を入力します。ページ全体のコードは、以下のとおりです。
<?php
include "dbcon.php";
include "functions.php";
if(isset($_GET['pid'])){
//clean pid
if(!is_numeric($_GET['pid'])){
//the value received is not numeric. redirect the user to login
header("location:login.php");
}
//otherwise clean the received value for query use
$cpid = mysql_escape_string($_GET['pid']);
}
$getname = "SELECT title FROM projects WHERE pid = '".$cpid."'";
$g_result = mysql_query($getname);
if(!$g_result){
echo mysql_error();
}else{
$rowname = mysql_fetch_assoc($g_result);
$title = $row['title'];
}
if(isset($_POST['submit'])){
//check vars
$sname=mysql_escape_string($_POST['s_name']);
$p_pid=mysql_escape_string($_POST['p_pid']);
//insert
$insert = "INSERT INTO staff SET name = '".$sname."',";
$insert .= "p_id= '".$p_pid."'";
if(!mysql_query($insert)){
echo mysql_error();
}else{
header("location:main.php");
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/PM_Main.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Untitled Document</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<link href="Templates/main.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="100%" border="0">
<tr>
<td width="33%"> </td>
<td width="28%"> </td>
<td width="39%">Logged in: <!-- InstanceBeginEditable name="login" -->
<? echo $_SESSION['name'];?> | <a href="logout.php">Logout</a><!-- InstanceEndEditable --></td>
</tr>
<tr>
<td colspan="3" bgcolor="#6699CC" class="headertxt">Project Management Software </td>
</tr>
<tr>
<td colspan="3"><!-- InstanceBeginEditable name="main" -->
<form id="form1" name="form1" method="post" action="add_staff.php" >
<table width="100%" border="0">
<tr>
<td colspan="2" class="loginheader"><?php echo $title;?></td>
</tr>
<tr>
<td colspan="2"><?php if(isset($msg)){
echo $msg;
}?> </td>
</tr>
<tr>
<td width="10%">Name </td>
<td width="90%"><label>
<input name="s_name" type="text" />
<input type="hidden" name="p_pid" value="<?php echo $_GET['pid'];?>"/>
</label></td>
</tr>
<tr>
<td> </td>
<td><label>
<input type="submit" name="submit" value="Add Member to Project" />
</label></td>
</tr>
</table>
</form><!-- InstanceEndEditable --></td>
</tr>
<tr>
<td colspan="3"><!-- InstanceBeginEditable name="nav" -->
<a href="main.php">View Project List</a> | <a href="admin/login.php">Administrators Corner </a><!-- InstanceEndEditable --></td>
</tr>
<tr>
<td align="right" class="cright" colspan="3">copyright © 2007 PM </td>
</tr>
</table>
</body>
<!-- InstanceEnd --></html>
Copyright © 2008 Ziff Davis Enterprise, Inc.
Originally appearing in the U.S. Edition of Dev Shed. All Rights Reserved.








