forked from yanvolo/chalk_it_up
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew_deck_processor.php
More file actions
33 lines (25 loc) · 935 Bytes
/
new_deck_processor.php
File metadata and controls
33 lines (25 loc) · 935 Bytes
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
<?php
require "library.php";
sql();
needUserInfo();
$deckID = base64_encode(random_bytes(16));
$name = san($_POST['name']);
$description = san($_POST['desc']);
$house = $_POST['cards'];
$card_ids = array();
txStart();
foreach($house as $card){
$id = base64_encode(random_bytes(16));
array_push($card_ids, $id);
for($i = 0; $i < count($card['answers']); $i++){
$card['answers'][$i] = san($card['answers'][$i]);
}
$answers_csv = str_putcsv($card['answers']);
runSql('new_card', 'INSERT INTO card (cardid, owner, short, long, answers_csv) VALUES ($1, $2, $3, $4, $5);',
array($id, $uid, san($card['question']), san($card['question']), $answers_csv));
}
runSql('new_deck', 'INSERT INTO deck (deckid, owner, display_name, description, questionids_csv) VALUES ($1, $2, $3, $4, $5);',
array($deckID, $uid, $name, $description, str_putcsv($card_ids)));
txCommit();
doneWithSql();
echo 'Success!';