1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
|
<?
require '../lib/global.php';
$dbh = GetDBConn();
if (!isset($_SESSION['user']) || !CheckUserPerm($dbh, $_SESSION['user'], $_SERVER['SCRIPT_NAME'])) {
Redirect('index.php');
}
$message = "";
if (isset($_REQUEST['id'])) {
$id = $_REQUEST['id'] + 0;
$content = CleanContent($_REQUEST['content']);
$updater = $_REQUEST['updater'] + 0;
if ($updater > 0) {
$sql = "UPDATE news SET title='" . Prep($_REQUEST['title']) . "', posted='" . Prep(GetInputDate("posted")) . "', content='" . Prep($content) . "', client_id='" . Prep($_REQUEST['client_id']) . "', deal='" . Prep($_REQUEST['deal']) . "', value='" . Prep($_REQUEST['value']) . "', pic1='" . Prep($_REQUEST['pic1']) . "', pic2='" . Prep($_REQUEST['pic2']) . "', pic3='" . Prep($_REQUEST['pic3']) . "' WHERE id=$id";
mysql_query($sql, $dbh);
Redirect("approve.php");
} else {
if ($id > 0) {
$sql = "DELETE FROM news WHERE updatefor=$id";
mysql_query($sql, $dbh);
}
$sql = "INSERT INTO news (title, posted, content, client_id, deal, value, pic1, pic2, pic3, updatefor) VALUES ('" . Prep($_REQUEST['title']) . "', '" . Prep(GetInputDate("posted")) . "', '" . Prep($content) . "', '" . Prep($_REQUEST['client_id']) . "', '" . Prep($_REQUEST['deal']) . "', '" . Prep($_REQUEST['value']) . "', '" . Prep($_REQUEST['pic1']) . "', '" . Prep($_REQUEST['pic2']) . "', '" . Prep($_REQUEST['pic3']) . "', $id)";
mysql_query($sql, $dbh);
$message = "<p>Your changes have been queued for approval.</p>";
}
}
AdminHeader($dbh, "News administration", null);
echo $message;
if (isset($_REQUEST['del'])) {
$id = $_REQUEST['del'] + 0;
$sql = "DELETE FROM news WHERE updatefor=$id";
mysql_query($sql, $dbh);
$sql = "UPDATE news SET updatefor=-1 WHERE id=$id";
mysql_query($sql, $dbh);
echo "<p>Your changes have been queued for approval.</p>";
}
if (isset($_REQUEST['edit'])) {
# Edit/Insert
$id = $_REQUEST['edit'] + 0;
$sql = "SELECT * FROM news, clients WHERE news.id=$id" ;
$res = mysql_query($sql, $dbh);
$rec = mysql_fetch_array($res);
$updater = 0;
if ($rec['updatefor'] != null){
$updater = 1;
}
?>
<script type="text/javascript">
wysSetHeaderContent('<link rel="stylesheet" href="../styles.css" />');
wysConvertTextarea('content', 1, 'WYSBODY template4');
</script>
<form action="<? echo $_SERVER['SCRIPT_NAME'] ?>" method="post">
<input type="hidden" name="id" value="<? echo $id ?>" />
<input type="hidden" name="updater" value="<? echo $updater ?>" />
<table>
<tr>
<td>Title</td>
<td>
<input type="text" name="title" value="<? echo str_replace('"', '"', $rec['title']) ?>" size="100" maxlength="200" style="width: 700px;" />
</td>
</tr>
<tr>
<td>Date</td>
<td>
<?
if ($id > 0) {
echo MakeInputDate("posted", $rec['posted']);
} else {
echo MakeInputDate("posted", date("Y-m-d"));
}
?>
</td>
</tr>
<tr>
<td>Details</td>
<td>
<textarea name="content" id="content" rows="5" cols="80" style="width: 700px; height: 350px;"><? echo $rec['content'] ?></textarea>
</td>
</tr>
<tr>
<td>Pictures</td>
<td>
<?
echo MakeFileSelector("pic1", array("$CFG_ADMINIMAGES/people", "$CFG_ADMINIMAGES/images", "$CFG_ADMINIMAGES/oldimages"), $rec['pic1'], "showPreview(this.options[this.selectedIndex].value)", '/\.(jpg|jpeg|gif|png)$/i', true);
echo MakeFileSelector("pic2", array("$CFG_ADMINIMAGES/people", "$CFG_ADMINIMAGES/images", "$CFG_ADMINIMAGES/oldimages"), $rec['pic2'], "showPreview(this.options[this.selectedIndex].value)", '/\.(jpg|jpeg|gif|png)$/i', true);
echo MakeFileSelector("pic3", array("$CFG_ADMINIMAGES/people", "$CFG_ADMINIMAGES/images", "$CFG_ADMINIMAGES/oldimages"), $rec['pic3'], "showPreview(this.options[this.selectedIndex].value)", '/\.(jpg|jpeg|gif|png)$/i', true);
?>
</td>
</tr>
<tr>
<td>Client</td>
<td>
<?
$strSQL = "SELECT id, name FROM clients ORDER BY name ASC";
$query = mysql_query($sql, $dbh);
$rs = mysql_fetch_assoc($query);
?>
<select name="client_id" size="1">
<option value="">Select client</option>
<? do { ?>
<option value="<? echo $rs['id']?>" <?php echo( $rs['id'] == $rec['client_id'] ? " selected=\"selected\"" : "" ); ?>>><? echo( $rs['name'] )?></option>
<?
} while ($rs = mysql_fetch_assoc($query));
$rows = mysql_num_rows($query);
if($rows > 0) {
mysql_data_seek($query, 0);
$rs = mysql_fetch_assoc($query);
}
?>
</select>
</td>
</tr>
<tr>
<td>Deal</td>
<td>
<input type="text" name="deal" value="<? echo str_replace('"', '"', $rec['deal']) ?>" size="100" maxlength="250" style="width: 700px;" /><br /><small>Leave blank if this news doesn't relate to a specific deal</small>
</td>
</tr>
<tr>
<td>Value</td>
<td>
<input type="text" name="value" value="<? echo str_replace('"', '"', $rec['value']) ?>" size="32" maxlength="64" />
</td>
</tr>
<tr>
<td colspan="2" align="right">
<input type="submit" value="Save" />
</td>
</tr>
</table>
</form>
<?
} else {
?>
<table class="full">
<tr>
<th>Title</th>
<th>Date</th>
<th>Client</th>
<th>Deal</th>
<th>Value</th>
<th></th>
</tr>
<?
$sql = "SELECT id, title, posted, client, deal, value FROM news WHERE updatefor IS NULL OR updatefor=-1 ORDER BY posted DESC, id DESC";
$res = mysql_query($sql, $dbh);
if (mysql_num_rows($res)) {
$cnt = 0;
while ($rec = mysql_fetch_array($res)) {
echo "<tr class=\"" . ($cnt++ % 2 ? 'even' : 'odd') . "\">";
echo "<td>" . $rec['title'] . "</td>";
echo "<td>" . FormatDate($rec['posted']) . "</td>";
echo "<td>" . $rec['client'] . "</td>";
echo "<td>" . AbbrevStr($rec['deal'], 50) . "</td>";
echo "<td>" . $rec['value'] . "</td>";
$id = $rec['id'];
echo "<td><a href=\"" . $_SERVER['SCRIPT_NAME'] . "?edit=$id\">Edit</a> ";
echo "<a href=\"" . $_SERVER['SCRIPT_NAME'] . "?del=$id\" onclick=\"return confirmDel('article');\">Delete</a></td>";
echo "</tr>";
}
} else {
echo "<tr><td colspan=\"6\">No news found</td></tr>";
}
?>
</table>
<p>
<a href="<? echo $_SERVER['SCRIPT_NAME'] ?>?edit=0">Add new news item</a>
</p>
<?
}
AdminFooter($dbh);
?>
|