2. Staff Requirement:- Login Staff
- View particular units which registered to staff
- View content, download content, edit content, update content.
- Create Content
- send notification to student view email or messaging
The "login staff "and" View particular unit which registered to a staff" are similar to "login student" (as it disccused earlier) so I will skip that to the next topic.
View content, download content, edit content, delete content.
when one of the unit has been click, material details will be shown in the material are. the different between this view content and student "view content" are: staff "view content will be able to delete and update material. see picture below:

Edit Content
in material.php (list all material script) I use this code to link the edit button to update page.
<a href='editContent.php?materialId=$row[m_id]'>Edit </a>
as we can see this link go to editContent.php.

<?php require_once('dmwp_connect.php');
$staffid = $_REQUEST['staffid'];
$materialId = $_REQUEST['materialId'];
//this is used for getting the right material to be edited. passing the $materialId from material.php page to this mysql syntac
$result = mysql_query("SELECT * FROM materials WHERE m_id= $materialId ;");
$row = mysql_fetch_array($result);
// get material name from material page which has been sent by httprequest
$materialName = $row['m_name'];
// get file name from material page which has been sent by httprequest
$fileName = $row['fileName'];
// get conten value from material page which has been sent by httprequest
$content = $row['content'];
mysql_close($con);
?>
<form enctype="multipart/form-data" action="editContentValid.php?m_id=<?php echo $materialId; //passing material id to editcontentValid to edit the right material ?>" method="POST">
<table width="462" border="1">
<input type="hidden" name="MAX_FILE_SIZE" value="100000000" />
<tr>
<td colspan="2" align="center">Edit Content</td>
</tr>
<tr>
<td width="148">Material Name</td>
<td width="298"><input type="text" name="materialName" value="<?php echo $materialName;?>" /></td>
</tr>
<tr>
<td>Attach File:</td>
<td><?php echo $fileName;?></td>
</tr>
<tr>
<td colspan="2"><textarea cols="55" rows="10" name="pending_text" id="pending_text" ><?php echo $content;?></textarea></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="Update" /></td>
</tr>
</table>
</form>
Then as soon as user pressed update button( which is submit button's type) the action will call editContentValid.php. This script will perform update selected material and recoreded into mysql database.
editContentValid.php
<?php require_once('dmwp_connect.php'); ?>
<?php
//get selected material which has been sent
$materialId = $_REQUEST['m_id'];
//get material's name which has been sent
$materialName = $_REQUEST['materialName'];
//get content's material which has been sent
$pending_text = $_REQUEST['pending_text'];
$date = date("d-m-Y");
//this mysql syntac will update selected material and recoreded in database
$sql="UPDATE materials SET m_name='$materialName', content='$pending_text' date='$date' WHERE m_id='$materialId'";
//if cannot connect to database show an error message
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
// show a message where update has been successful
mysql_close($con);
echo "<div align='center'>";
echo "Update Content has been successful!";
echo "<br/>";
//go back to priviouse page
echo "<a href='javascript:history.back(-3);'>ok</a>";
echo "</div>";
?>
Delete content
Delete button is quite simple. as soon as the button is pressed, it links to delete script which will delete the material form database.
this is the code that I have used to perform delete action:
material.php
<div ";
echo "onclick = 'getDataReturnText(" ;
//this will call the scrpit to delete selected material
echo '"deleteMaterial.php?m_id=" + ' ;
echo "$m_id ," ;
echo " callback2)'>" ;
echo "<a href ='#'><img src='images/delete.png' /></a>";
echo "</div>";
deleteMaterial.php
<?php require_once('dmwp_connect.php'); ?>
<?php
//get material id from material.php page.
//it will be used to specify which material will be deleted
$m_id = $_REQUEST['m_id'];
//mysql syntac which will delete data from datbase
mysql_query("DELETE FROM materials WHERE m_id=$m_id;");
mysql_close($con);
//successful message will be display
echo "<div align='center'>";
echo "Your data has been deleted";
echo "<br/>";
//go back to the list
echo "<a href='javascript:history.go(0)'>ok</a>";
echo "</div>";
?>
Create Content

as we can see from the picture above, uploadFile has been click and "create material" table has been placed.
<?php
$valueOK = $_REQUEST['id'];
//get create content table and replace material area in curren page.
echo " onclick ='getDataReturnText(";
//get the specify table for staff
echo '"upload.php?staffid=" + ';
echo "$valueOK ," ;
echo " content_area)'>";
?>
When the submit button is pressed, the system will check wheater the content is valid. if not error message will be displayed.
bellow is the code that I use for createing new material
uploader.php
<?php require_once('dmwp_connect.php'); ?>
<?php
// Where the file is going to be placed
$target_path = "uploads/";
$fileName = $_FILES['uploadedfile']['name'];
$materialName = $_REQUEST['materialName'];
$pending_text = $_REQUEST['pending_text'];
//the date is specify when new material has been created
$date = date("d-m-Y");
//* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$staffid = $_REQUEST['staffid'];
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
//can not create new material if title and content is empty
if($materialName == null || $pending_text == null) {
echo "<div align='center'>";
echo "There was an error uploading the file, please try again!";
echo "<br/>";
echo "<a href='javascript:history.back(-1);'>ok</a>";
echo "</div>";
// will be able to create attachment file and uploaded to the server.
} else if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)){
echo "<div align='center'>";
echo "The file ".$materialName." - ". basename( $_FILES['uploadedfile']['name'])." has been uploaded";
echo "<br/>";
echo "<a href='staffPage.php?id=$staffid'>ok</a>";
echo "</div>";
//insert material into database
$sql="INSERT INTO materials (m_name, m_url, date, u_id, content, fileName)
VALUES('$_POST[materialName]','../".$upload."/uploads/".
$fileName."','".$date."','$_POST[unit_id]','$_REQUEST[pending_text]','$fileName')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
mysql_close($con);
}
//will be able to create content without uploaded file attached
else {
echo "<div align='center'>";
echo "The file ".$materialName." - ". basename( $_FILES['uploadedfile']['name'])." has been uploaded";
echo "<br/>";
echo "<a href='staffPage.php?id=$staffid'>ok</a>";
echo "</div>";
//insert material into database
$sql="INSERT INTO materials (m_name, m_url, date, u_id, content, fileName)
VALUES('$_POST[materialName]','../".$upload."/uploads/".
$fileName."','".$date."','$_POST[unit_id]','$_REQUEST[pending_text]','$fileName')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
}
?>
Send notification to student view email or messaging

StudentRead.PhP is used for listing all student providing checkbox to select what sending system will be used. there are two system can be selected, which are send message via Email and/or SMS (text message)
This is the following code:
<?php require_once('../dmwp_connect.php'); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Form</title>
</head>
<body>
<p class="p">Select student to notify:</p>
//sendEmail.PHP will be run as soon as the button is pressed
<form action="phpmailer/sendEmail.php" method="post">
<?php
// connecting to database and display error message if fail
if(!mysql_select_db($dbname, $con))
{echo"db failed!";};
//get all student which belong to particular course
$result = mysql_query("SELECT std_name ,
std_email, std_first, std_last,
c.course_name, phone_no FROM student s ,
courses c WHERE s.course_id = c.course_id ");
while($row = mysql_fetch_array($result))
{
//print student follow by checked box - this check box will be used to send validation to the sendemail script. if the check box is Checked then email will be sent to student email
echo "<input type='checkbox' name='incoming_mailto[]'
value=$row[std_email]> $row[std_last]".",
"."$row[std_first]"." - "."$row[course_name]"." - "."</input>";
//print checked box - this check box will be used to send validation to the sendemail script
//if the check box is Checked then SMS will be sent to student mobile
echo "<input type='checkbox' name='incoming_smsto[]'
value=$row[phone_no]> send sms </input><br>";
};
?>
<br><br>
<input type="submit" value="Send notification">
</form>
</body>
</html>
sendEmail.php - This PHP script is used for sending and email or/and sending test message to student. "red" text will be described the script.
<?php require_once('../dmwp_connect.php'); ?>
<?php
require("class.phpmailer.php");
// validation check, if no checkbox has been checked throw this error message
if($_POST['incoming_mailto'] == false && $_POST['incoming_smsto'] == false){
echo "<div align='center'>Please select one of the address<br/><a href='javascript:history.back(-1);'>ok</a></div>";
}
// validation check, if email checkbox has been checked then send the email
else if($_POST['incoming_mailto']){
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "auth.smtp.1and1.co.uk"; // specify main and backup server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "info@ismedad.co.uk"; // SMTP username
$mail->Password = "******"; // SMTP password - this has been changed for security reason
$mail->From = "info@ismedad.co.uk";
$mail->FromName = "Harry";
//get email address from .phpmailer/studentRead.php
//send email to student by using loop it allows sending multiple email
foreach($_POST['incoming_mailto'] as $emailAddress){
$mail->AddAddress($emailAddress);
}
//validation check, if send sms checkbox has been checked then send the message
if($_POST['incoming_smsto']){
//get phone number from .phpmailer/studentRead.php
//send text message to student by using loop. it allows sending multiple test message
foreach($_POST['incoming_smsto'] as $phoneNo){
//send text message to student mobile phone which has a value "new material has been uploded, Please check your account af LSBU M-Learning"
fopen("http://dynamic.lsbu.ac.uk/sms.php?destination=".$phoneNo."&message=New+material+has+been+uploaded,+Please+check+your+account+at+LSBU+M-Learning&username=alasharh","r");
}
}
$mail->AddReplyTo("info@ismedad.co.uk", "Information");
$mail->WordWrap = 50; // set word wrap to 50 characters
//$mail->AddAttachment("/var/tmp/file.tar.gz"); // add attachments
//$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); // optional name
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = "LSBU M-Learning";
//body of an email
$mail->Body = "New material has been uploaded, Please check your account at LSBU M-Learning";
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
// if email can not be deliver show error message below
if(!$mail->Send())
{
echo "<div align='center'>";
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
echo "<br/>";
// go back to previous page
echo "<a href='javascript:history.back(-1);'>ok</a>";
echo "</div>";
exit;
}
// if email has been sucessfuly deliver show the following message
echo "<div align='center'>";
echo "Message has been sent";
echo "<br/>";
// it use to go back to main page
echo "<a href='javascript:history.back(-1);'>ok</a>";
echo "</div>";
}
//validation check, if only send sms checkbox has been checked send text message.
else if($_POST['incoming_smsto']){
foreach($_POST['incoming_smsto'] as $phoneNo){
fopen("http://dynamic.lsbu.ac.uk/sms.php?destination=$phoneNo&message=the_ugliest_person_is_YOU!!!&username=alasharh","r");
echo "<div align='center'>";
echo "Message has been sent";
echo "<br/>";
echo "<a href='javascript:history.back(-1);'>ok</a>";
echo "</div>";
}
}
?>