include_once "lib/http_service.php"; include_once "lib/model_json.php"; damas_service::init_http(); damas_service::accessGranted(); damas_service::allowed("model::" . arg("cmd")); if (!arg("cmd")) { header("HTTP/1.1: 400 Bad Request"); echo "Bad command"; exit; } header('Content-type: application/json'); $ret = false; switch (arg("cmd")) { /* SCRUD operations */ case "search": echo json_encode(model::search(json_decode(arg("keys")), arg("sortby"), arg("order"), arg("limit"))); break; case "create": if (is_null(arg('keys'))) { header("HTTP/1.1: 400 Bad Request"); echo "Bad command"; exit; } $id = model::create(json_decode(arg("keys"))); if (!$id) { header("HTTP/1.1: 409 Conflict"); echo "create Error, please change your values"; exit; } echo json_encode(model_json::node($id, 1, $NODE_TAG | $NODE_PRM)); break;
/** * Retrieve the children of a node * @param {Integer} $id node index * @return {Array} array of children ids */ static function children($id) { $res = array(); // PROTOTYPE BEGIN $protoname = model::getKey($id, 'prototype'); if ($protoname) { $proto = model::searchKey('id', $protoname); $proto = $proto[0]; if ($proto) { $res = model::children($proto); } } // PROTOTYPE END return $res + model::search(array('#parent' => '= ' . $id)); }
echo $msg . '. No change made.'; exit; } if (!is_uploaded_file($file['tmp_name'])) { header("HTTP/1.1: 409 Conflict"); echo $file['name'] . ": is_uploaded_file returned false. Possible break attempt. No change made."; exit; } $dir = ''; $path = ''; $id = ''; if (model::getKey(arg('id'), 'dir')) { // we are in a dir $dir = model::getKey(arg('id'), 'dir'); $path = $dir . '/' . $file['name']; $id = array_shift(model::search(array('file' => "='" . $path . "'"))); } else { $path = model::getKey(arg('id'), 'file'); $dir = dirname($path); $id = arg('id'); } $error_detected = false; if (!is_writable($assetsLCL . $dir)) { $error_detected = true; $msg .= $dir . " is not writable. "; } if ($id) { // replacement checks switch (model::getKey($id, 'mode')) { case '1': default: