2017-05-04 11:22:23 +00:00
|
|
|
|
<?php
|
2021-02-16 11:23:00 +00:00
|
|
|
|
namespace Controls;
|
2017-05-04 11:22:23 +00:00
|
|
|
|
|
2021-02-16 11:42:27 +00:00
|
|
|
|
function button_tag(string $value, string $type, $attributes = "") {
|
|
|
|
|
return "<button dojoType=\"dijit.form.Button\" $attributes type=\"$type\">".htmlspecialchars($value)."</button>";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function submit_tag(string $value, $attributes = "") {
|
|
|
|
|
return button_tag($value, "submit", "class=\"alt-primary\" $attributes");
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-16 11:23:00 +00:00
|
|
|
|
function select_tag(string $name, $value, array $values, string $attributes = "", string $id = "") {
|
|
|
|
|
$dojo_type = strpos($attributes, "dojoType") === false ? "dojoType='fox.form.Select'" : "";
|
2017-05-04 11:22:23 +00:00
|
|
|
|
|
2021-02-16 11:23:00 +00:00
|
|
|
|
$rv = "<select $dojo_type name=\"".htmlspecialchars($name)."\"
|
|
|
|
|
id=\"".htmlspecialchars($id)."\" name=\"".htmlspecialchars($name)."\" $attributes>";
|
2017-05-04 11:22:23 +00:00
|
|
|
|
|
2021-02-16 11:23:00 +00:00
|
|
|
|
foreach ($values as $v) {
|
|
|
|
|
$is_sel = ($v == $value) ? "selected=\"selected\"" : "";
|
2017-05-04 11:22:23 +00:00
|
|
|
|
|
2021-02-16 11:23:00 +00:00
|
|
|
|
$rv .= "<option value=\"".htmlspecialchars($v)."\" $is_sel>".htmlspecialchars($v)."</option>";
|
|
|
|
|
}
|
2017-05-04 11:22:23 +00:00
|
|
|
|
|
2021-02-16 11:23:00 +00:00
|
|
|
|
$rv .= "</select>";
|
2017-05-04 11:22:23 +00:00
|
|
|
|
|
2021-02-16 11:23:00 +00:00
|
|
|
|
return $rv;
|
|
|
|
|
}
|
2017-05-04 11:22:23 +00:00
|
|
|
|
|
2021-02-16 11:23:00 +00:00
|
|
|
|
function select_labels(string $name, string $value, string $attributes = "", string $id = "") {
|
|
|
|
|
$pdo = \Db::pdo();
|
2017-05-04 11:22:23 +00:00
|
|
|
|
|
2021-02-16 11:23:00 +00:00
|
|
|
|
$sth = $pdo->prepare("SELECT caption FROM ttrss_labels2
|
|
|
|
|
WHERE owner_uid = ? ORDER BY caption");
|
|
|
|
|
$sth->execute([$_SESSION['uid']]);
|
2017-05-04 11:22:23 +00:00
|
|
|
|
|
2021-02-16 11:23:00 +00:00
|
|
|
|
$values = [];
|
2017-05-04 11:22:23 +00:00
|
|
|
|
|
2021-02-16 11:23:00 +00:00
|
|
|
|
while ($row = $sth->fetch()) {
|
|
|
|
|
array_push($values, $row["caption"]);
|
|
|
|
|
}
|
2021-02-12 11:31:36 +00:00
|
|
|
|
|
2021-02-16 11:23:00 +00:00
|
|
|
|
return select_tag($name, $value, $values, $attributes, $id);
|
|
|
|
|
}
|
2017-05-04 11:22:23 +00:00
|
|
|
|
|
2021-02-16 11:23:00 +00:00
|
|
|
|
function select_hash(string $name, $value, array $values, string $attributes = "", string $id = "") {
|
|
|
|
|
$dojo_type = strpos($attributes, "dojoType") === false ? "dojoType='fox.form.Select'" : "";
|
2017-05-04 11:22:23 +00:00
|
|
|
|
|
2021-02-16 11:23:00 +00:00
|
|
|
|
$rv = "<select $dojo_type name=\"".htmlspecialchars($name)."\"
|
|
|
|
|
id=\"".htmlspecialchars($id)."\" name=\"".htmlspecialchars($name)."\" $attributes>";
|
2021-02-12 11:31:36 +00:00
|
|
|
|
|
2021-02-16 11:23:00 +00:00
|
|
|
|
foreach ($values as $k => $v) {
|
|
|
|
|
$is_sel = ($k == $value) ? "selected=\"selected\"" : "";
|
2017-05-04 11:22:23 +00:00
|
|
|
|
|
2021-02-16 11:23:00 +00:00
|
|
|
|
$rv .= "<option value=\"".htmlspecialchars($k)."\" $is_sel>".htmlspecialchars($v)."</option>";
|
|
|
|
|
}
|
2017-05-04 11:22:23 +00:00
|
|
|
|
|
2021-02-16 11:23:00 +00:00
|
|
|
|
$rv .= "</select>";
|
2017-05-04 11:22:23 +00:00
|
|
|
|
|
2021-02-16 11:23:00 +00:00
|
|
|
|
return $rv;
|
|
|
|
|
}
|
2017-05-04 11:22:23 +00:00
|
|
|
|
|
2021-02-16 11:23:00 +00:00
|
|
|
|
function hidden_tag(string $name, string $value) {
|
|
|
|
|
return "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\"
|
2021-02-16 12:27:22 +00:00
|
|
|
|
name=\"".htmlspecialchars($name)."\" value=\"$value\">";
|
2021-02-16 11:23:00 +00:00
|
|
|
|
}
|
2017-05-04 11:22:23 +00:00
|
|
|
|
|
2021-02-16 12:05:32 +00:00
|
|
|
|
function checkbox_tag(string $name, bool $checked = false, string $value = "", string $attributes = "", string $id = "") {
|
2021-02-16 11:23:00 +00:00
|
|
|
|
$is_checked = $checked ? "checked" : "";
|
|
|
|
|
$value_str = $value ? "value=\"".htmlspecialchars($value)."\"" : "";
|
2017-05-04 11:22:23 +00:00
|
|
|
|
|
2021-02-16 11:23:00 +00:00
|
|
|
|
return "<input dojoType='dijit.form.CheckBox' name=\"".htmlspecialchars($name)."\"
|
2021-02-16 12:05:32 +00:00
|
|
|
|
$value_str $is_checked $attributes id=\"".htmlspecialchars($id)."\">";
|
2021-02-16 11:23:00 +00:00
|
|
|
|
}
|
2017-05-04 11:22:23 +00:00
|
|
|
|
|
2021-02-16 11:23:00 +00:00
|
|
|
|
function select_feeds_cats(string $name, int $default_id = null, string $attributes = "",
|
|
|
|
|
bool $include_all_cats = true, string $root_id = null, int $nest_level = 0, string $id = "") {
|
2017-12-01 12:10:05 +00:00
|
|
|
|
|
2021-02-16 11:23:00 +00:00
|
|
|
|
$ret = "";
|
2017-07-02 17:37:52 +00:00
|
|
|
|
|
2021-02-16 11:23:00 +00:00
|
|
|
|
if (!$root_id) {
|
|
|
|
|
$ret .= "<select name=\"".htmlspecialchars($name)."\"
|
|
|
|
|
id=\"".htmlspecialchars($id)."\"
|
|
|
|
|
default=\"".((string)$default_id)."\"
|
|
|
|
|
dojoType=\"fox.form.Select\" $attributes>";
|
|
|
|
|
}
|
2017-07-02 17:37:52 +00:00
|
|
|
|
|
2021-02-16 11:23:00 +00:00
|
|
|
|
$pdo = \Db::pdo();
|
2017-07-02 17:37:52 +00:00
|
|
|
|
|
2021-02-16 11:23:00 +00:00
|
|
|
|
if (!$root_id) $root_id = null;
|
2017-07-02 17:37:52 +00:00
|
|
|
|
|
2021-02-16 11:23:00 +00:00
|
|
|
|
$sth = $pdo->prepare("SELECT id,title,
|
|
|
|
|
(SELECT COUNT(id) FROM ttrss_feed_categories AS c2 WHERE
|
|
|
|
|
c2.parent_cat = ttrss_feed_categories.id) AS num_children
|
|
|
|
|
FROM ttrss_feed_categories
|
|
|
|
|
WHERE owner_uid = :uid AND
|
|
|
|
|
(parent_cat = :root_id OR (:root_id IS NULL AND parent_cat IS NULL)) ORDER BY title");
|
|
|
|
|
$sth->execute([":uid" => $_SESSION['uid'], ":root_id" => $root_id]);
|
2017-07-02 17:37:52 +00:00
|
|
|
|
|
2021-02-16 11:23:00 +00:00
|
|
|
|
$found = 0;
|
2017-12-01 12:10:05 +00:00
|
|
|
|
|
2021-02-16 11:23:00 +00:00
|
|
|
|
while ($line = $sth->fetch()) {
|
|
|
|
|
++$found;
|
2017-07-02 17:37:52 +00:00
|
|
|
|
|
2021-02-16 11:23:00 +00:00
|
|
|
|
if ($line["id"] == $default_id) {
|
|
|
|
|
$is_selected = "selected=\"1\"";
|
|
|
|
|
} else {
|
|
|
|
|
$is_selected = "";
|
|
|
|
|
}
|
2017-07-02 17:37:52 +00:00
|
|
|
|
|
2021-02-16 11:23:00 +00:00
|
|
|
|
for ($i = 0; $i < $nest_level; $i++)
|
|
|
|
|
$line["title"] = " " . $line["title"];
|
2017-07-02 17:37:52 +00:00
|
|
|
|
|
2021-02-16 11:23:00 +00:00
|
|
|
|
if ($line["title"])
|
|
|
|
|
$ret .= sprintf("<option $is_selected value='%d'>%s</option>",
|
|
|
|
|
$line["id"], htmlspecialchars($line["title"]));
|
2017-07-02 17:37:52 +00:00
|
|
|
|
|
2021-02-16 11:23:00 +00:00
|
|
|
|
if ($line["num_children"] > 0)
|
|
|
|
|
$ret .= select_feeds_cats($id, $default_id, $attributes,
|
|
|
|
|
$include_all_cats, $line["id"], $nest_level+1, $id);
|
|
|
|
|
}
|
2017-07-02 17:37:52 +00:00
|
|
|
|
|
2021-02-16 11:23:00 +00:00
|
|
|
|
if (!$root_id) {
|
|
|
|
|
if ($include_all_cats) {
|
|
|
|
|
if ($found > 0) {
|
|
|
|
|
$ret .= "<option disabled=\"1\">―――――――――――――――</option>";
|
|
|
|
|
}
|
2017-07-02 17:37:52 +00:00
|
|
|
|
|
2021-02-16 11:23:00 +00:00
|
|
|
|
if ($default_id == 0) {
|
|
|
|
|
$is_selected = "selected=\"1\"";
|
|
|
|
|
} else {
|
|
|
|
|
$is_selected = "";
|
|
|
|
|
}
|
2017-07-02 17:37:52 +00:00
|
|
|
|
|
2021-02-16 11:23:00 +00:00
|
|
|
|
$ret .= "<option $is_selected value=\"0\">".__('Uncategorized')."</option>";
|
|
|
|
|
}
|
|
|
|
|
$ret .= "</select>";
|
|
|
|
|
}
|
2017-12-01 12:10:05 +00:00
|
|
|
|
|
2021-02-16 11:23:00 +00:00
|
|
|
|
return $ret;
|
|
|
|
|
}
|
2017-07-02 17:37:52 +00:00
|
|
|
|
|