$Action = (isset($_REQUEST['Action'])) ? $_REQUEST['Action'] : '';
$Save = (isset($_REQUEST['Save'])) ? $_REQUEST['Save'] : '';
$SubAction = (isset($_REQUEST['SubAction'])) ? $_REQUEST['SubAction'] : '';
$AttachmentID = (isset($_REQUEST['AttachmentID'])) ? $_REQUEST['AttachmentID'] : '';
$AttachmentName = (isset($_REQUEST['AttachmentName'])) ? $_REQUEST['AttachmentName'] : '';
$AttachmentDescription = (isset($_REQUEST['AttachmentDescription'])) ? $_REQUEST['AttachmentDescription'] : '';
$Status = (isset($_REQUEST['Status'])) ? $_REQUEST['Status'] : 1;
$AddAttachment = (isset($_REQUEST['AddAttachment'])) ? $_REQUEST['AddAttachment'] : '';
$CloseWindow = (isset($_GET['CloseWindow']) && $_GET['CloseWindow'] == 1) ? 1 : 0;
$alllists = '';
$OUTPUT = '';
if($Action == 'Add')
{
$FORM_ITEMS[$FORM_REQUIRED_ITEM . "Attachment File"]="file|AttachmentFile";
$HELP_ITEMS["AttachmentFile"]["Title"] = "Attachment File";
$HELP_ITEMS["AttachmentFile"]["Content"] = "Select a file from your local hard drive to use as an attachment.";
$FORM_ITEMS[-1]="submit|Next »:1-attachments";
$FORM=new AdminForm;
$FORM->title="CreateAttachment";
$FORM->items=$FORM_ITEMS;
$FORM->action=MakeAdminLink("attachments?Action=CreateAttachment&AddAttachment=1&CloseWindow=" .$CloseWindow);
$FORM->MakeForm("New Attachment Details");
$FORM->output = "Complete the form below to create a new attachment.
Click on the \"Next\" button to continue." . $FORM->output;
$OUTPUT.=MakeBox("Create Attachment (Step 1 of 2)",$FORM->output);
$OUTPUT .= '
';
}
if($Action=='CreateAttachment')
{
$Error = '';
$AttachmentName = $_FILES['AttachmentFile']['name'];
$AttachmentDescription = $AttachmentName;
mysql_query("INSERT INTO " . $TABLEPREFIX . "attachments SET AttachmentName='".addslashes($AttachmentName)."', AttachmentDescription='".addslashes($AttachmentDescription)."', Status='".addslashes($Status)."', DateEntered='".addslashes($SYSTEMTIME)."', AdminID='" . addslashes($CURRENTADMIN['AdminID']) . "'");
$AttachmentID=mysql_insert_id();
if(isset($AttachmentName) && $AttachmentID > 0) {
$old_file = $_FILES['AttachmentFile']['tmp_name'];
$parts = explode('.', $AttachmentName);
$ext = array_pop($parts);
$new_file = '../temp/attachments/' . $AttachmentID . '.' . $ext;
if (!move_uploaded_file($old_file, $new_file)) {
$Error = 'Unable to upload ' . $new_file;
} else {
if (!SAFE_MODE) {
@chmod($new_file, 0644);
}
}
} else {
$Error = 'Unable to upload file ' . $AttachmentName;
}
if($Error){
$OUTPUT .= MakeErrorBox("Invalid File", $Error);
}else{
mysql_query("UPDATE " . $TABLEPREFIX . "attachments SET AttachmentFilename='".addslashes($new_file)."' WHERE AttachmentID='".addslashes($AttachmentID)."'");
$Action="EditAttachment";
}
}
if($Action=='EditAttachment'){
if($Save){
mysql_query("UPDATE " . $TABLEPREFIX . "attachments SET AttachmentName='".addslashes($AttachmentName)."', AttachmentDescription='".addslashes($AttachmentDescription)."', Status='".addslashes($Status)."', DateEntered='".addslashes($SYSTEMTIME)."' WHERE AttachmentID='".addslashes($AttachmentID)."'");
if ($AddAttachment == 1) {
$title = "Attachment Created Successfully";
$msg = "The attachment has been created successfully.";
} else {
$title = "Attachment Updated Successfully";
$msg = "The attachment has been updated successfully.";
}
$OUTPUT .= MakeSuccessBox($title, $msg, MakeAdminLink("attachments?Action=&CloseWindow=".$CloseWindow));
}else{
$attachment=mysql_fetch_assoc(mysql_query("SELECT * FROM " . $TABLEPREFIX . "attachments WHERE AttachmentID='".addslashes($AttachmentID)."'"));
$FORM_ITEMS[$FORM_REQUIRED_ITEM . "Name"]="textfield|AttachmentName:100:44:".$attachment['AttachmentName'];
$HELP_ITEMS["AttachmentName"]["Title"] = "Attachment Name";
$HELP_ITEMS["AttachmentName"]["Content"] = "Enter a name for this attachment. This is what the subscriber will see the attachment name as. eg \'brochure.pdf\'";
$FORM_ITEMS[$FORM_REQUIRED_ITEM . "Description"]="textfield|AttachmentDescription:100:44:".$attachment['AttachmentDescription'];
$HELP_ITEMS["AttachmentDescription"]["Title"] = "Attachment Description";
$HELP_ITEMS["AttachmentDescription"]["Content"] = "Enter a description for this attachment. This name is for your reference only, such as \'Brochure of my product\'.";
$FORM_ITEMS[$FORM_REQUIRED_ITEM . "Status"]="select|Status:1:1->Active;0->Inactive;:".$attachment["Status"];
$HELP_ITEMS["Status"]["Title"] = "Status";
$HELP_ITEMS["Status"]["Content"] = "Is this attachment active? If so, you will be able to add it to your content when composing a newsletter.";
$FORM_ITEMS["-1"]="submit|Finish:1-attachments";
$FORM=new AdminForm;
$FORM->title="EditAttachment";
$FORM->items=$FORM_ITEMS;
$link = "attachments?Action=EditAttachment&Save=Yes&AttachmentID=$AttachmentID&CloseWindow=".$CloseWindow;
if ($AddAttachment == 1) $link .= '&AddAttachment=1';
$FORM->action=MakeAdminLink($link);
$FORM->MakeForm("Attachment Details");
if($AddAttachment == "1")
{
$FORM->output = "Complete the form below to finish adding an attachment." . $FORM->output;
$OUTPUT.=MakeBox("Create Attachment (Step 2 of 2)",$FORM->output);
}
else
{
$FORM->output = "Complete the form below to finish editing this attachment." . $FORM->output;
$OUTPUT.=MakeBox("Edit Attachment",$FORM->output);
}
$OUTPUT .= '
';
}
}
if ($Action=='') {
if ($CloseWindow) {
?>
0) {
$filename = mysql_result($file_result, 0, 0);
if(is_file($filename)) unlink($filename);
}
mysql_query("DELETE FROM " . $TABLEPREFIX . "attachments WHERE AttachmentID='".addslashes($AttachmentID)."'");
}
$query = "SELECT * FROM " . $TABLEPREFIX . "attachments";
if (!isset($CURRENTADMIN['Manager']) || $CURRENTADMIN['Manager'] != 1) $query .= " WHERE AdminID='".addslashes($CURRENTADMIN['AdminID'])."'";
$query .= " ORDER BY AttachmentName ASC";
$attachments_result = mysql_query($query);
$Total = mysql_num_rows($attachments_result);
if($Total > 0)
{
//currently defined attachments!
$LO='
Use the form below to preview, edit and delete your attachments.
To create a new attachment, click on the "Create Attachment" button below.
| Attachment Name | Description | Date Created | Action | |
|
|
' . $attachment["AttachmentName"] . ' | ' . $attachment["AttachmentDescription"] . ' | ' . DisplayDate($attachment["DateEntered"]) . ' | '; $LO .= MakeLink("attachments?Action=EditAttachment&AttachmentID=".$attachment['AttachmentID'],'Edit'); $LO .= " "; $LO .= MakeConfirmBox("attachments?Action=&SubAction=DeleteAttachment&AttachmentID=".$attachment['AttachmentID'],"Delete","Are you sure you wish to delete this attachment?"); $LO .= " "; $filename = substr(strrchr($attachment['AttachmentFilename'], '/'), 1); $url = 'Preview'; $LO .= $url; $LO .= ' |