summaryrefslogtreecommitdiff
path: root/lib/list/inc_process.php
blob: d4656b549f79255c0ec5ffeaa6b107fd70ac8f31 (plain) (blame)
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
<?php

require("lib/JSON/inc_json.php");

function mk_batch_json($models, $contents) {
	$data = array("columns" => array(), "items" => array());

	$columns = explode('|', $models);
	foreach ($columns as $c) {
		if ($c[0] == '!') {
			$data['columns'][] = array("question" => false, "name" => substr($c, 1));
		} else {
			$data['columns'][] = array("question" => true, "name" => $c);
		}
	}

	$items = explode("\n", $contents);
	foreach($items as $i) {
		$ii = explode('|', str_replace("\r", '', $i));
		if (count($ii) == count($columns)) {
			$data['items'][] = $ii;
		}
	}

	return json_encode($data);
}