blob: 5fc55c8767dedcf276300477adb729fc992f9564 [file] [log] [blame]
<?php
/*******************************************************************************
* Copyright (c) 2006 Eclipse Foundation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Wayne Beaton (Eclipse Foundation)- initial API and implementation
*******************************************************************************/
#*****************************************************************************
#
# edit_resource.php
#
# Author: Wayne Beaton
# Date: February 16, 2006
#
# Description:
# This file is used to edit resources.
#****************************************************************************
include ('scripts/common.php');
include ('scripts/sql.php');
$broker = new ResourceBroker();
$id = get_get_parameter('id');
if ($id == null) {
$id = get_post_parameter('id');
$action = get_post_parameter('action');
if ($id == null) {
if ($action == "create_resource") {
$title = get_post_parameter('resource_title');
$description = get_post_parameter('resource_description');
$type = get_post_parameter('resource_type');
$image = get_post_parameter('resource_image');
$categories = get_post_parameter('resource_categories');
$id = $broker->create_resource($title, $description, $type, $image, $categories);
}
} else {
if ($action == "update_resource") {
$title = get_post_parameter('resource_title');
$description = get_post_parameter('resource_description');
$type = get_post_parameter('resource_type');
$image = get_post_parameter('resource_image');
$categories = get_post_parameter('resource_categories');
$broker->update_resource($id, $title, $description, $type, $image, $categories);
} else if ($action == "delete_resource") {
$broker->delete_resource($id);
goto_list_resources();
} else if ($action == "add_categories") {
$category_ids = get_post_parameter('category');
$broker->add_categories($id, $category_ids);
} else if ($action == "update_link") {
$link_id = get_post_parameter('link_id');
$title = get_post_parameter('link_title');
$language = get_post_parameter('link_language');
$date = get_post_parameter('link_date');
$path = get_post_parameter('link_path');
$type = get_post_parameter('link_type');
$authors = get_post_parameter('link_authors');
$broker->update_link($id, $link_id, $title, $language, $date, $path, $type, $authors);
} else if ($action == "delete_link") {
$link_id = get_post_parameter('link_id');
$broker->delete_link($link_id);
}else if ($action == "create_link") {
$title = get_post_parameter('link_title');
$language = get_post_parameter('link_language');
$date = get_post_parameter('link_date');
$path = get_post_parameter('link_path');
$type = get_post_parameter('link_type');
$authors = get_post_parameter('link_authors');
$broker->create_link($id, $title, $language, $date, $path, $type, $authors);
}
}
}
include("scripts/header.php");
display_messages($broker->messages);
function get_selected($parameter, $value) {
global $type;
return $type == $value ? 'selected' : '';
}
if ($id != null) {
$result = mysql_query("select id, title, type, description, image_path from resource where id=$id");
if ($error = mysql_error()) {
echo "Error querying resources: $error<br/>";
exit;
}
if ($row = mysql_fetch_array($result)) {
$id = $row[0];
$title = $row[1];
$type = $row[2];
$description = $row[3];
$image_path = $row[4];
$categories = $broker->get_resource_categories_string($id);
} else {
echo "No resource found with id=$id";
exit;
}
} else {
$title = "New Resource";
$type = "article";
$description = "Description";
$image_path = "";
}
?>
<div class="section">
<h3><?= $id == null ? 'Create' : 'Edit' ?> Resource</h3>
<?php
if ($id != null) {
?>
<form method="post" action="edit_resource.php">
<input type="hidden" name="action" value="delete_resource"/>
<input type="hidden" name="id" value="<?= $id ?>"/>
<p><input type="submit" value="Delete"/></p>
</form>
<?php
}
?>
<form method="post" action="edit_resource.php">
<input type="hidden" name="action" value="<?= $id == null ? 'create_resource' : 'update_resource' ?>"/>
<input type="hidden" name="id" value="<?= $id ?>"/>
<table>
<tr><td>Title: *</td><td><input type="text" style="width: 500px;" name="resource_title" value="<?= $title ?>"/></td></tr>
<tr><td valign="top">Description: *</td>
<td>
<textarea style="width: 500px;" rows="5" name="resource_description"><?= $description ?></textarea><br/>
The description should <b>not</b> contain HTML markup.
</td>
</tr>
<tr><td>Type: *</td><td>
<select name="resource_type">
<option value="article" <?= get_selected($type, 'article') ?>>Eclipse Corner Article</option>
<option value="publication" <?= get_selected($type, 'publication') ?>>Article from another source</option>
<option value="study" <?= get_selected($type, 'study') ?>>Case study</option>
<option value="book" <?= get_selected($type, 'book') ?>>Book</option>
<option value="presentation" <?= get_selected($type, 'presentation') ?>>Presentation</option>
<option value="demo" <?= get_selected($type, 'demo') ?>>Demonstration</option>
<option value="webinar" <?= get_selected($type, 'webinar') ?>>Webinar</option>
<option value="podcast" <?= get_selected($type, 'podcast') ?>>Podcast</option>
<option value="code" <?= get_selected($type, 'code') ?>>Code Sample</option>
<option value="course" <?= get_selected($type, 'course') ?>>Course</option>
<option value="other" <?= get_selected($type, 'other') ?>>Other</option>
</select>
</td></tr>
<tr><td>Image Path:</td><td><input type="text" style="width: 500px;" name="resource_image" value="<?= $image_path ?>"/></td></tr>
<tr><td>Categories:</td><td><input type="text" style="width: 500px;" name="resource_categories" value="<?= $categories ?>"/></td></tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="<?= $id == null ? 'Add' : 'Update' ?>"/> <input type="reset" value="Reset"/>
</td>
<tr>
</table>
</form>
</div>
<?php
if ($id != null) {
?>
<div class="section">
<h3>Add to Categories</h3>
<form method="post" action="edit_resource.php">
<input type="hidden" name="action" value="add_categories"/>
<input type="hidden" name="id" value="<?= $id ?>"/>
<table><tbody><tr>
<?php
$result = mysql_query("select id, name from category order by name");
if ($error = mysql_error()) {
echo "Error querying categories: $error<br/>";
exit;
}
$index = 0;
while ($row = mysql_fetch_array($result)) {
$category_id = $row[0];
$category_name = $row[1];
if ($index % 5 == 0) echo "</tr><tr>";
$index++;
?>
<td><input type="checkbox" name="category[<?= $index ?>]" value="<?= $category_id ?>"><?= $category_name ?></input></td>
<?php
}
?>
</tr></tbody></table>
<p style="align:center"><input type="submit" value="Add Categories"/> <input type="reset" value="Reset"/></p>
</form>
</div>
<?php
$type_suggestions = $broker->get_type_suggestions_string();
$language_suggestions = $broker->get_language_suggestions_string();
$result = mysql_query("select id, type, title, language, path, create_date from link where resource_id=$id");
if ($error = mysql_error()) {
echo "Error querying authors: $error<br/>";
exit;
}
$index = 0;
while ($row = mysql_fetch_array($result)) {
$link_id = $row[0];
$type = $row[1];
$title = $row[2];
$language = $row[3];
$path = $row[4];
$date = $row[5];
$link_authors = $broker->get_link_authors_string($link_id);
$index++;
?>
<div class="section">
<h3>Link #<?= $index ?></h3>
<form method="post" action="edit_resource.php">
<input type="hidden" name="action" value="delete_link"/>
<input type="hidden" name="id" value="<?= $id ?>"/>
<input type="hidden" name="link_id" value="<?= $link_id ?>"/>
<p><input type="submit" value="Delete"/></p>
</form>
<form method="post" action="edit_resource.php">
<input type="hidden" name="action" value="update_link"/>
<input type="hidden" name="id" value="<?= $id ?>"/>
<input type="hidden" name="link_id" value="<?= $link_id ?>"/>
<table>
<tr><td>Link Path: *</td><td><input type="text" style="width: 500px;" name="link_path" value="<?= $path ?>"/></td></tr>
<tr><td>Link Title:</td><td><input type="text" style="width: 500px;" name="link_title" value="<?= $title ?>"/></td></tr>
<tr><td>Link Date: *</td><td><input type="text" style="width: 500px;" name="link_date" value="<?= $date ?>"/></td></tr>
<tr>
<td>Link Language: *</td>
<td>
<input type="text" size="2" name="link_language" value="<?= $language ?>"/>
Suggested values: <?= $language_suggestions ?>.
</td>
</tr>
<tr>
<td>
Link Type: *</td><td><input type="text" size="2" name="link_type" value="<?= $type ?>"/>
Suggested values: <?= $type_suggestions ?>.
</td>
</tr>
<tr>
<td valign="top">Link Authors:</td>
<td width="550">
<input type="text" style="width: 500px;" name="link_authors" value="<?= $link_authors ?>"/><br/>
Enter author names here (separated by commas). If authors with these names already exist in the
database, those existing authors will be used. New authors will be created as necessary.
</td>
</tr>
<tr>
<td align="center" colspan="2">
<input type="submit" value="Update"/> <input type="reset" value="Reset"/>
</td>
</tr>
</table>
</form>
</div>
<?php
}
}
if ($id != null) {
?>
<div class="section">
<h3>New Link</h3>
<form method="post" action="edit_resource.php">
<input type="hidden" name="action" value="create_link"/>
<input type="hidden" name="id" value="<?= $id ?>"/>
<table>
<tr><td>Link Path: *</td><td><input type="text" style="width: 500px;" name="link_path"/></td></tr>
<tr><td>Link Title:</td><td><input type="text" style="width: 500px;" name="link_title"/></td></tr>
<tr><td>Link Date: *</td><td><input type="text" style="width: 500px;" name="link_date"/></td></tr>
<tr>
<td>Link Language: *</td>
<td>
<input type="text" size="2" name="link_language" value="en"/>
Suggested values: <?= $language_suggestions ?>.
</td>
</tr>
<tr>
<td>
Link Type: *
</td>
<td>
<input type="text" size="2" name="link_type" value="html"/>
Suggested values: <?= $type_suggestions ?>.
</td>
</tr>
<tr>
<td valign="top">Link Authors:</td>
<td width="550">
<input type="text" style="width: 500px;" name="link_authors"/><br/>
Enter author names here (separated by commas). If authors with these names already exist in the
database, those existing authors will be used. New authors will be created as necessary.
</td>
</tr>
<tr>
<td align="center" colspan="2">
<input type="submit" value="Add"/>
</td>
</tr>
</table>
</form>
</div>
<?php
}
include("scripts/footer.php");
?>