function OnPageLoad() { echo new XhtmlElement('h1', Html::Encode('Delete category: ' . $this->data_object->GetName())); if ($this->deleted) { ?> <p>The category has been deleted.</p> <p><a href="/yesnosorry/categorylist.php">View all categories</a></p> <?php } else { if ($this->has_permission) { ?> <p>Deleting a category cannot be undone.</p> <ul> <li>Its competitions will not be listed in a category</li> </ul> <p>Are you sure you want to delete this category?</p> <form action="<?php echo Html::Encode($this->data_object->GetDeleteCategoryUrl()); ?> " method="post" class="deleteButtons"> <div> <input type="submit" value="Delete category" name="delete" /> <input type="submit" value="Cancel" name="cancel" /> </div> </form> <?php } else { ?> <p>Sorry, you're not allowed to delete this category.</p> <p><a href="/yesnosorry/categorylist.php">Go back to the list of categories</a></p> <?php } } }
/** * @return int * @param Category $o_category * @desc Save the supplied Category to the database, and return the id */ function Save($o_category) { # check parameters if (!$o_category instanceof Category) { die('Unable to save category'); } # build query # if no id, it's a new category; otherwise update the category if ($o_category->GetId()) { $s_sql = 'UPDATE ' . $this->GetSettings()->GetTable('Category') . ' SET ' . 'parent = ' . Sql::ProtectNumeric($o_category->GetParentId(), true) . ', ' . "name = " . Sql::ProtectString($this->GetDataConnection(), $o_category->GetName()) . ", " . "code = " . Sql::ProtectString($this->GetDataConnection(), $o_category->GetUrl()) . ", " . 'sort_override = ' . Sql::ProtectNumeric($o_category->GetSortOverride()) . ', ' . 'date_changed = ' . gmdate('U') . ' ' . 'WHERE id = ' . Sql::ProtectNumeric($o_category->GetId()); # run query $this->GetDataConnection()->query($s_sql); } else { $s_sql = 'INSERT INTO ' . $this->GetSettings()->GetTable('Category') . ' SET ' . 'parent = ' . Sql::ProtectNumeric($o_category->GetParentId(), true) . ', ' . "name = " . Sql::ProtectString($this->GetDataConnection(), $o_category->GetName()) . ", " . "code = " . Sql::ProtectString($this->GetDataConnection(), $o_category->GetUrl()) . ", " . 'sort_override = ' . Sql::ProtectNumeric($o_category->GetSortOverride()) . ', ' . 'date_added = ' . gmdate('U') . ', ' . 'date_changed = ' . gmdate('U'); # run query $o_result = $this->GetDataConnection()->query($s_sql); # get autonumber $o_category->SetId($this->GetDataConnection()->insertID()); } return $o_category->GetId(); }
} } elseif ($id and Filter::input('delete', 'post', 'bool')) { $category = new Category($id); if ($category->Delete()) { $info .= lng('CAT_DELETED'); } else { $info .= lng('CAT_NOT_EXIST'); } $id = false; } $cat_list = CategoryManager::GetList($id); include View::Get('category_header.html', $st_subdir . 'category/'); if ($id) { $cat_item = new Category($id); if ($cat_item->Exist()) { $cat_name = $cat_item->GetName(); $cat_desc = $cat_item->GetDescription(); $cat_priority = $cat_item->GetPriority(); include View::Get('category_edit.html', $st_subdir . 'category/'); if (!$cat_item->IsSystem()) { include View::Get('category_delete.html', $st_subdir . 'category/'); } } unset($cat_item); } else { include View::Get('category_add.html', $st_subdir . 'category/'); } break; case 'group': // Пустое название группы $name = Filter::input('name');
private function CreateItem(Category $category) { $o_link = new XhtmlElement('a', Html::Encode($category->GetName())); $o_link->AddAttribute('href', 'categoryedit.php?item=' . $category->GetId()); return new XhtmlElement('li', $o_link); }
public static function GetNameByID($id) { if (!$id or $id < 0) { return 'Без категории'; } $cat_item = new Category($id); $category_name = $cat_item->GetName(); unset($cat_item); if (!$category_name) { return 'Без категории'; } else { return $category_name; } }