manage-metatypes.php
106 lines
| 3.3 KiB
| text/x-php
|
PhpLexer
| r1 | <?php | |||
| require_once('include/admin.inc.php'); | ||||
| auth_redirect(); // Require logged in user to access this page. | ||||
| if( isset($_GET['delete']) && (int)$_GET['delete'] ) { | ||||
| check_nonce('delete-metatype-'.(int)$_GET['delete']); | ||||
| r35 | if(! $dbConnection->executeUpdate('DELETE FROM meta_t WHERE id = ?', array($_GET['delete']))) | |||
| r1 | { | |||
| adminlog("Error on deleting metatype ".(int)$_GET['delete'], MTS_TYPE_META, MTA_DELETE, E_WARNING); | ||||
| r35 | mtdie("Error on update: ". $dbConnection->errorCode()); | |||
| r1 | } | |||
| $info.='<p>Deleted metatype successfully.<p>'; | ||||
| adminlog("Metatype ".(int)$_GET['delete']." deleted.", MTS_TYPE_META, MTA_DELETE); | ||||
| } | ||||
| if( isset($_POST['action']) && $_POST['action'] == 'new_meta' ) { | ||||
| check_nonce('new-metatype'); | ||||
| r5 | ||||
| r1 | $name = trim($_POST['name']); | |||
| r5 | ||||
| r1 | if( check_type_name( $name ) ) { | |||
| r35 | if(! $dbConnection->executeUpdate('INSERT INTO meta_t (name) VALUES (?)', array($name))) | |||
| r1 | { | |||
| adminlog("Error on inserting metatype ".(int)$_GET['delete'], MTS_TYPE_META, MTA_INSERT, E_WARNING); | ||||
| r35 | mtdie("Error on insertion: ". $dbConnection->errorCode()); | |||
| r1 | } | |||
| } | ||||
| $info.='<p>New metatype created successfully.<p>'; | ||||
| adminlog("Metatype ".$name." added.", MTS_TYPE_META, MTA_ADD); | ||||
| } | ||||
| if( isset($_POST['action']) && $_POST['action'] == 'edit_meta' ) { | ||||
| check_nonce('save-metatype-'.(int)$_POST['type_id']); | ||||
| r5 | ||||
| r1 | $name = trim($_POST['name']); | |||
| r5 | ||||
| r1 | if( check_type_name( $name ) ) { | |||
| r35 | if(! $dbConnection->executeUpdate('UPDATE meta_t SET name = ? WHERE id = ?', array($name, $_POST['type_id']))) | |||
| r1 | { | |||
| adminlog("Error updating metatype ".(int)$_GET['delete'], MTS_TYPE_META, MTA_UPDATE, E_WARNING); | ||||
| r35 | mtdie("Error on update: ". $dbConnection->errorCode()); | |||
| r1 | } | |||
| } | ||||
| $info.='<p>Changes to metatype saved successfully.<p>'; | ||||
| adminlog("Metatype ".$name." updated.", MTS_TYPE_META, MTA_UPDATE); | ||||
| } | ||||
| //get all metatypes | ||||
| r35 | $metas = $dbConnection->fetchAll('SELECT id, name FROM meta_t'); | |||
| r1 | ||||
| adminhead('Metatypes'); | ||||
| adminmenu(); | ||||
| ?> | ||||
| <h2>Metatype Management</h2> | ||||
| <p>Make changes to the metatypes which organize the types.</p> | ||||
| <table class="widefat"> | ||||
| <thead> | ||||
| <tr> | ||||
| <th scope="col" style="text-align: center;">Metatype #</th> | ||||
| <th scope="col">Name</th> | ||||
| <th scope="col"></th> | ||||
| <th scope="col"></th> | ||||
| </tr> | ||||
| </thead> | ||||
| <tbody id="the-list"> | ||||
| <?php | ||||
| $alternate=false; | ||||
| foreach( $metas as $s ) { | ||||
| $alternate=!$alternate; | ||||
| ?> | ||||
| <tr id="type-<?php echo $s->id; ?>" <?php if($alternate) echo 'class="alternate"'; ?>> | ||||
| <th scope="row" style="text-align: center;"><?php echo $s->id; ?></th> | ||||
| <td><?php echo htmlentities($s->name); ?></td> | ||||
| <td style="text-align: center;"><a href="edit-metatype.php?edit=<?php echo (int)$s->id; ?>">Edit</a></td> | ||||
| <td style="text-align: center;"><a class="delete" href="?delete=<?php echo (int)$s->id; ?>">Delete</a></td> | ||||
| </tr> | ||||
| <?php | ||||
| } | ||||
| ?> | ||||
| </tbody> | ||||
| </table> | ||||
| <form enctype="multipart/form-data" name="create-user" id="create-user" action="manage-metatypes.php" method="post"> | ||||
| <?php nonce_field('new-metatype'); ?> | ||||
| <input type="hidden" name="action" value="new_meta" /> | ||||
| <h2>Create New Metatype</h2> | ||||
| <div class="narrow"> | ||||
| <table class="editform" width="100%" cellspacing="2" cellpadding="5"> | ||||
| <tr> | ||||
| <th scope="row" width="33%">Name</th> | ||||
| <td width="66%"><input name="name" type="text" id="name" value="" /></td> | ||||
| </tr> | ||||
| </table> | ||||
| r5 | ||||
| r1 | <p class="submit"><input type="submit" value="Create »" name="submit" /></p> | |||
| </div> | ||||
| </form> | ||||
| <?php | ||||
| adminfooter(); | ||||
| r5 | ?> | |||
