| | 45 | |
| | 46 | public function show_settings() { |
| | 47 | |
| | 48 | ?><a href="index.php?action=edit_plugin_setting&plugin=acronyms&id=0"><?php echo gettext("create new"); ?></a><?php |
| | 49 | foreach ($this->_acronyms as $id => $acro) { |
| | 50 | ?> |
| | 51 | <div class="log_post"> |
| | 52 | <div class="log_post_head"> |
| | 53 | <h1 class="log_post_h1"><a href="?action=edit_plugin_setting&plugin=acronyms&id=<?php echo $id; ?>"><?php echo stripslashes($acro[0]); ?></a></h1> |
| | 54 | </div> |
| | 55 | <div class="log_post_body"> |
| | 56 | <div class="log_post_normal"> |
| | 57 | <?php echo stripslashes($acro[1]); ?> |
| | 58 | </div> |
| | 59 | </div> |
| | 60 | <div class="log_post_foot"> |
| | 61 | </div> |
| | 62 | </div> |
| | 63 | <?php |
| | 64 | } |
| | 65 | } |
| | 66 | |
| | 67 | public function edit_setting($requestdata) { |
| | 68 | $id = $requestdata["id"]; |
| | 69 | if ($id == 0) { |
| | 70 | $acro["id"] = 0; |
| | 71 | $acro["acronym"] = "acronym name"; |
| | 72 | $acro["description"] = "acronym description"; |
| | 73 | } else { |
| | 74 | $acro = array( |
| | 75 | "id" => $id, |
| | 76 | "acronym" => $this->_acronyms[$id][0], |
| | 77 | "description" => $this->_acronyms[$id][1] |
| | 78 | ); |
| | 79 | } |
| | 80 | ?> |
| | 81 | <form name="acronym" method="post" action="index.php"> |
| | 82 | <input type="hidden" name="action" value="save_plugin_setting" /> |
| | 83 | <input type="hidden" name="plugin" value="acronyms" /> |
| | 84 | <input type="hidden" name="acro[action]" id="act" value="" /> |
| | 85 | <input type="hidden" name="acro[id]" value="<?php echo $acro["id"]; ?>" /> |
| | 86 | <div class="log_post"> |
| | 87 | <div class="log_post_head"> |
| | 88 | <h1 class="log_post_h1"><input type="text" name="acro[acronym]" value="<?php echo stripslashes($acro["acronym"]); ?>" /></h1> |
| | 89 | </div> |
| | 90 | <div class="log_post_body"> |
| | 91 | <input type="text" name="acro[description]" value="<?php echo stripslashes($acro["description"]); ?>" style="width: 500px;" /><br /> |
| | 92 | <input type="submit" value="<?php echo gettext("save"); ?>" /> |
| | 93 | <?php if ($id) { ?> |
| | 94 | <input type="button" value="<?php echo gettext("delete"); ?>" onClick="document.getElementById('act').value='delete';document.forms.acronym.submit();" /> |
| | 95 | <?php } ?> |
| | 96 | </div> |
| | 97 | <div class="log_postfoot"> |
| | 98 | </div> |
| | 99 | </div> |
| | 100 | </form> |
| | 101 | <?php |
| | 102 | } |
| | 103 | |
| | 104 | public function save_setting($requestdata) { |
| | 105 | $acro = $requestdata["acro"]; |
| | 106 | if ($acro["action"] == "delete") { |
| | 107 | /* remove acro */ |
| | 108 | unset($this->_acronyms[$acro["id"]]); |
| | 109 | $sql = sprintf("DELETE FROM acronyms WHERE id=%d", $acro["id"]); |
| | 110 | $this->_mvblog->db->query($sql); |
| | 111 | } else { |
| | 112 | if ($acro["id"]) { |
| | 113 | $this->_acronyms[$acro["id"]] = array($acro["acronym"], $acro["description"]); |
| | 114 | /* store it in db */ |
| | 115 | $sql = sprintf("UPDATE acronyms SET acronym='%s', description='%s' WHERE id=%d", $acro["acronym"], $acro["description"], $acro["id"]); |
| | 116 | $this->_mvblog->db->query($sql); |
| | 117 | } else { |
| | 118 | $sql = sprintf("INSERT INTO acronyms (acronym, description) values ('%s', '%s')", $acro["acronym"], $acro["description"]); |
| | 119 | $res = $this->_mvblog->db->query($sql); |
| | 120 | /* fetch the same record so we can get the id */ |
| | 121 | $sql = sprintf("SELECT id FROM acronyms WHERE acronym='%s' AND description='%s'", $acro["acronym"], $acro["description"]); |
| | 122 | $res = $this->_mvblog->db->query($sql); |
| | 123 | $res->fetchInto($row); |
| | 124 | $this->_acronyms[$row[0]] = array($acro["acronym"], $acronym["description"]); |
| | 125 | } |
| | 126 | } |
| | 127 | $this->show_settings(); |
| | 128 | } |