Loading plugins/template/template.cpp +30 −0 Changes for plugins/template/template.cpp: 30 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -565,11 +565,41 @@ namespace blogi { std::vector<char> sbuf; dbpp::SQL sql; dbpp::DBResult res; // Check for existing template with same layer + type bool overwrite = false; if (params) { json_object *ow_obj = nullptr; if (json_object_object_get_ex(params, "overwrite", &ow_obj)) { overwrite = json_object_get_boolean(ow_obj); } } sql << "SELECT id FROM templates WHERE layer='" << dbpp::SQL::escaped(sbuf, layer.c_str()) << "' AND type=" << type << " LIMIT 1;"; int dupCount = Args->database[tid]->exec(sql, res); if (dupCount > 0 && !overwrite) { json_object_object_add(response, "status", json_object_new_string("duplicate")); json_object_object_add(response, "message", json_object_new_string(tr(_lang,"A template with this layer and device type already exists. Overwrite?").c_str())); json_object_object_add(response, "existing_id", json_object_new_int(atoi(res[0][0]))); return; } else if (dupCount > 0 && overwrite) { int eid = atoi(res[0][0]); sql.clear(); sql << "UPDATE templates SET html='" << dbpp::SQL::escaped(sbuf, html.c_str()) << "' WHERE id=" << eid << ";"; Args->database[tid]->exec(sql, res); } else { sql.clear(); sql << "INSERT INTO templates (layer, html, type) VALUES ('" << dbpp::SQL::escaped(sbuf, layer.c_str()) << "', '" << dbpp::SQL::escaped(sbuf, html.c_str()) << "', " << type << ");"; Args->database[tid]->exec(sql, res); } json_object_object_add(response, "status", json_object_new_string("success")); json_object_object_add(response, "message", json_object_new_string(tr(_lang,"Published to template layer!").c_str())); Loading Loading
plugins/template/template.cpp +30 −0 Changes for plugins/template/template.cpp: 30 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -565,11 +565,41 @@ namespace blogi { std::vector<char> sbuf; dbpp::SQL sql; dbpp::DBResult res; // Check for existing template with same layer + type bool overwrite = false; if (params) { json_object *ow_obj = nullptr; if (json_object_object_get_ex(params, "overwrite", &ow_obj)) { overwrite = json_object_get_boolean(ow_obj); } } sql << "SELECT id FROM templates WHERE layer='" << dbpp::SQL::escaped(sbuf, layer.c_str()) << "' AND type=" << type << " LIMIT 1;"; int dupCount = Args->database[tid]->exec(sql, res); if (dupCount > 0 && !overwrite) { json_object_object_add(response, "status", json_object_new_string("duplicate")); json_object_object_add(response, "message", json_object_new_string(tr(_lang,"A template with this layer and device type already exists. Overwrite?").c_str())); json_object_object_add(response, "existing_id", json_object_new_int(atoi(res[0][0]))); return; } else if (dupCount > 0 && overwrite) { int eid = atoi(res[0][0]); sql.clear(); sql << "UPDATE templates SET html='" << dbpp::SQL::escaped(sbuf, html.c_str()) << "' WHERE id=" << eid << ";"; Args->database[tid]->exec(sql, res); } else { sql.clear(); sql << "INSERT INTO templates (layer, html, type) VALUES ('" << dbpp::SQL::escaped(sbuf, layer.c_str()) << "', '" << dbpp::SQL::escaped(sbuf, html.c_str()) << "', " << type << ");"; Args->database[tid]->exec(sql, res); } json_object_object_add(response, "status", json_object_new_string("success")); json_object_object_add(response, "message", json_object_new_string(tr(_lang,"Published to template layer!").c_str())); Loading