| 1 | <?php |
|---|
| 2 | require_once(WCF_DIR.'lib/system/event/EventListener.class.php'); |
|---|
| 3 | require_once(WCF_DIR.'lib/acp/form/DatabaseCategoryEditForm.class.php'); |
|---|
| 4 | |
|---|
| 5 | /** |
|---|
| 6 | * Shows the additonalRatings in the Webdisk-Item |
|---|
| 7 | * |
|---|
| 8 | * @author Markus Gerdelmann |
|---|
| 9 | * @copyright 2005-2009 |
|---|
| 10 | * @package de.wbb-security.database.additionalrating |
|---|
| 11 | */ |
|---|
| 12 | class DatabaseAdditionalRatingCategoryACPListener extends DatabaseCategoryEditForm { |
|---|
| 13 | |
|---|
| 14 | private $catID = 0; |
|---|
| 15 | private $fields = array(); |
|---|
| 16 | private $ratingID = 0; |
|---|
| 17 | private $edit = 0; |
|---|
| 18 | private $rating = array(); |
|---|
| 19 | private $field = ''; |
|---|
| 20 | private $sortOrder = 0; |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | /** |
|---|
| 24 | * @see EventListener::readFormParameters() |
|---|
| 25 | */ |
|---|
| 26 | public function readFormParameters() { |
|---|
| 27 | parent::readFormParameters(); |
|---|
| 28 | |
|---|
| 29 | if(isset($_POST['field'])) $this->field = StringUtil::Trim($_POST['field']); |
|---|
| 30 | if(isset($_POST['sortOrder'])) $this->sortOrder = intval($_POST['sortOrder']); |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | /** |
|---|
| 34 | * @see EventListener::readParameters() |
|---|
| 35 | */ |
|---|
| 36 | public function readParameters() { |
|---|
| 37 | parent::readParameters(); |
|---|
| 38 | |
|---|
| 39 | if(isset($_REQUEST['ratingID'])) $this->ratingID = intval($_REQUEST['ratingID']); |
|---|
| 40 | if(isset($_REQUEST['edit'])) $this->edit = intval($_REQUEST['edit']); |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | /** |
|---|
| 44 | * @see EventListener::validate() |
|---|
| 45 | */ |
|---|
| 46 | public function validate() { |
|---|
| 47 | parent::validate(); |
|---|
| 48 | |
|---|
| 49 | if (empty($this->field)) { |
|---|
| 50 | throw new UserInputException('field'); |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | if ($this->sortOrder == 0) { |
|---|
| 54 | throw new UserInputException('sortOrder'); |
|---|
| 55 | } |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | /** |
|---|
| 59 | * @see EventListener::execute() |
|---|
| 60 | */ |
|---|
| 61 | public function execute($eventObj, $className, $eventName){ |
|---|
| 62 | |
|---|
| 63 | // Hier wird die aktuelle KategoryID ausgelesen |
|---|
| 64 | $this->catID = $eventObj->categoryID; |
|---|
| 65 | |
|---|
| 66 | if ($this->edit == 1 && $this->ratingID > 0) { |
|---|
| 67 | |
|---|
| 68 | $sql = "SELECT * |
|---|
| 69 | FROM `wcf".WCF_N."_database_additionalrating` |
|---|
| 70 | WHERE `ratingID` = '".$this->ratingID."' |
|---|
| 71 | "; |
|---|
| 72 | $result = WCF::getDB()->sendQuery($sql); |
|---|
| 73 | while ($row = WCF::getDB()->fetchArray($result)) { |
|---|
| 74 | $this->rating[] = $row; |
|---|
| 75 | } |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | if ($this->catID > 0) { |
|---|
| 80 | |
|---|
| 81 | //Hier werden die vorhandenen Felder geladen. |
|---|
| 82 | $sql = "SELECT * |
|---|
| 83 | FROM `wcf".WCF_N."_database_additionalrating` |
|---|
| 84 | WHERE `catID` = '".$this->catID."' |
|---|
| 85 | ORDER by `sortOrder` ASC |
|---|
| 86 | "; |
|---|
| 87 | |
|---|
| 88 | $result = WCF::getDB()->sendQuery($sql); |
|---|
| 89 | while ($row = WCF::getDB()->fetchArray($result)) { |
|---|
| 90 | $this->fields[] = $row; |
|---|
| 91 | } |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | //Hier werden die Variablen in den Template-Variabeln registriert |
|---|
| 95 | WCF::getTPL()->assign(array( |
|---|
| 96 | 'fields' => $this->fields, |
|---|
| 97 | 'catID' => $this->catID, |
|---|
| 98 | 'field' => $this->field, |
|---|
| 99 | 'sortOrder' => $this->sortOrder |
|---|
| 100 | )); |
|---|
| 101 | |
|---|
| 102 | //Hier wird das Template in den Platzhalter der databaseItem.tpl geladen |
|---|
| 103 | if(!defined("DATABASE_ADDITIONALRATING_CATEGORY_TPL")) { |
|---|
| 104 | WCF::getTPL()->append('additionalFields2', WCF::getTPL()->fetch('databaseAdditionalRatingCategory')); |
|---|
| 105 | define("DATABASE_ADDITIONALRATING_CATEGORY_TPL",1); |
|---|
| 106 | } |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | /** |
|---|
| 110 | * @see EventListener::save() |
|---|
| 111 | */ |
|---|
| 112 | public function save() { |
|---|
| 113 | parent::save(); |
|---|
| 114 | |
|---|
| 115 | if (!empty($this->field) && $this->catID > 0) { |
|---|
| 116 | |
|---|
| 117 | $sql = "INPUT INTO `wcf".WCF_N."_database_additionalrating` |
|---|
| 118 | (`catID`, `field`, `sortOrder`) |
|---|
| 119 | VALUES ('".escapeString($this->catID)."', '".escapeString($this->field)."', '".escapeString($this->sortOrder)."') |
|---|
| 120 | "; |
|---|
| 121 | |
|---|
| 122 | WCF::getDB()->sendQuery($sql); |
|---|
| 123 | |
|---|
| 124 | $this->field = ''; |
|---|
| 125 | $this->sortOrder = 0; |
|---|
| 126 | |
|---|
| 127 | WCF::getTPL()->assign(array( |
|---|
| 128 | 'success' => true |
|---|
| 129 | )); |
|---|
| 130 | } |
|---|
| 131 | } |
|---|
| 132 | } |
|---|
| 133 | ?> |
|---|