summaryrefslogtreecommitdiff
path: root/lib/list/addbatch.php
diff options
context:
space:
mode:
authorNicolas BERNSTEIN <alexis211@gmail.com>2011-11-20 13:39:47 +0100
committerNicolas BERNSTEIN <alexis211@gmail.com>2011-11-20 13:39:47 +0100
commitd45c7f14891d951f8a6987cc6492073b97e05b5b (patch)
treed6467b1202c27f67fd8e894d25fd4aea0085b559 /lib/list/addbatch.php
parent4d7e065c2d2ec407b6a7ebfc7569628bac9149d1 (diff)
downloadBits-d45c7f14891d951f8a6987cc6492073b97e05b5b.tar.gz
Bits-d45c7f14891d951f8a6987cc6492073b97e05b5b.zip
Added the bit list study system
Diffstat (limited to 'lib/list/addbatch.php')
-rw-r--r--lib/list/addbatch.php43
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/list/addbatch.php b/lib/list/addbatch.php
new file mode 100644
index 0000000..5cb5fb6
--- /dev/null
+++ b/lib/list/addbatch.php
@@ -0,0 +1,43 @@
+<?php
+
+require("lib/list/inc_process.php");
+
+assert_redir(count($args) == 3, 'list');
+$listid = intval($args[2]);
+
+$list = mysql_fetch_assoc(sql(
+ "SELECT lists.id AS id, lists.name AS name, lists.owner AS owner_id ".
+ "FROM lists WHERE lists.id = $listid"));
+assert_error($list && $list['owner_id'] == $user['id'],
+ "This list does not exist, or you are not allowed to edit it.");
+
+$batch_name = "";
+$batch_model = "";
+$batch_contents = "";
+if (isset($_POST['name']) && isset($_POST['model']) && isset($_POST['contents'])) {
+ $batch_name = esca($_POST['name']);
+ $batch_model = esca($_POST['model']);
+ $batch_contents = esca($_POST['contents']);
+ $batch_json = mk_batch_json($batch_model, $batch_contents);
+ if ($batch_name == "") {
+ $error = "You must give a name to this batch.";
+ } else if (mysql_fetch_assoc(sql("SELECT id FROM batches WHERE list = $listid AND name = '" . escs($batch_name) . "'"))) {
+ $error = "You already have a batch using that name.";
+ } else {
+ sql(
+ "INSERT INTO batches(list, name, model, contents, json_data) ".
+ "VALUES($listid, '" . escs($batch_name) . "', '" . escs($batch_model) . "', '" . escs($batch_contents) . "', '" . escs($batch_json) . "')");
+ header("Location: view-list-$listid");
+ die();
+ }
+}
+
+$title = "Add batch to " . $list['name'];
+$fields = array(
+ array("label" => "Name : ", "name" => "name", "value" => $batch_name),
+ array("label" => "Columns : ", "name" => "model", "value" => $batch_model),
+ array("label" => "Contents : ", "name" => "contents", "type" => "textarea", "value" => $batch_contents)
+);
+$validate = "Add batch";
+
+require("tpl/list/ef.php");