executeUpdate('DELETE FROM strip_t WHERE id = ?', array($_GET['delete']))) { adminlog("Error deleting type ".(int)$_GET['delete'], MTS_TYPE, MTA_DELETE, E_WARNING); mtdie("Error on deletion of existing type: " . $dbConnection->errorCode(), 'SQL Error'); } if(false === $dbConnection->executeUpdate('DELETE FROM meta WHERE type = ?', array($_GET['delete']))) { adminlog("Error on deletion of type ".(int)$_GET['delete']."'s metadata.", MTS_TYPE, MTA_DELETE, E_WARNING); mtdie("Error on deletion of existing type's metadata: " . $dbConnection->errorCode(), 'SQL Error'); } $info.='
Deleted type successfully.
'; adminlog("Deleted type ".(int)$_GET['delete'], MTS_TYPE, MTA_DELETE); } if( isset($_POST['action']) && $_POST['action'] == 'new_type' ) { check_nonce('new-type'); $name = trim($_POST['name']); $desc = trim($_POST['description']); if( check_type_name($name) ) { if(! $dbConnection->executeUpdate('INSERT INTO strip_t (name, description) VALUES (?, ?)', array($name, $desc))) { adminlog("Error on insertion of new type.", MTS_TYPE, MTA_INSERT, E_WARNING); mtdie("Error on insertion of new type: ". $dbConnection->errorCode(), 'SQL Error'); } } $info.='
New type created successfully.
'; adminlog("Type '".$name."' created successfully.", MTS_TYPE, MTA_ADD); } if( isset($_POST['action']) && $_POST['action'] == 'edit_type' ) { $id = (int)$_POST['type_id']; check_nonce("save-type-$id"); $name = trim($_POST['name']); $desc = trim($_POST['description']); $meta = $_POST['meta']; $m_delete = $dbConnection->fetchAll('SELECT meta FROM meta WHERE type = ?', array($id)); $m_insert = array(); // Key listed in both Insert and Delete lists, so remove from both == Do Nothing foreach( $m_delete as $k=>$v ) { if( array_key_exists( $v->meta, $meta ) ) { unset($m_delete[$k]); unset($meta[$v->meta]); } else { $m_delete[$k] = 'meta=' . (int)$v->meta; } } // Key listed only in Insert list, make proper format foreach( $meta as $k=>$v ) { $m_insert[] = "($id," . (int)$k . ')'; } if( check_type_name( $name ) ) { if( !$dbConnection->executeUpdate('UPDATE strip_t SET name = ?, description = ? WHERE id = ?', array($name, $desc, $id))) { adminlog("Error on updating type ".$id, MTS_TYPE, MTA_UPDATE, E_WARNING); mtdie("Error on update of existing type: ". $dbConnection->errorCode(), 'SQL Error'); } $sql_insert = "INSERT INTO meta (type,meta) VALUES " . implode(',',$m_insert); $sql_delete = "DELETE FROM meta WHERE type=$id AND ( " . implode(' OR ',$m_delete) . ' )'; $dbConnection->beginTransaction(); if( count($m_insert) ) if(! $dbConnection->executeUpdate( $sql_insert ) ) { adminlog("Error inserting new metatype association data for type ".$id, MTS_TYPE, MTA_INSERT, E_WARNING); mtdie("There was an error inserting new metatype association data. Transaction aborted. $sql_insert"); } if( count($m_delete) ) if(! $dbConnection->executeUpdate( $sql_delete ) ) { adminlog("Error deleting old metatype association data for type ".$id, MTS_TYPE, MTA_REMOVE, E_WARNING); mtdie("There was an error deleting old metatype data. Transaction aborted. $sql_delete"); } $dbConnection->commit(); } else { $error.='
Invalid type name!
'; } $info.='Changes to type saved successfully.
'; adminlog("Type ".$id." updated.", MTS_TYPE, MTA_UPDATE); } //display all types $types = $dbConnection->fetchAll('SELECT strip_t.id AS id, strip_t.name AS name, strip_t.description AS description, COUNT(strip.id) AS strips FROM strip_t LEFT JOIN strip ON strip.type = strip_t.id GROUP BY strip_t.id'); adminhead('Types'); adminmenu(); ?>
Make changes to the types which categorize the comics.
| Type # | Name | Description | Strips | Metatypes | ||
|---|---|---|---|---|---|---|
| id; ?> | name); ?> | description); ?> | strips ?> | Edit | Delete |