0 AND cr_id <> -1 ORDER BY cr_id ASC ;', COPYRIGHTS_ADMIN); $result = pwg_query($query); $EAcopyrights = array(); while ($row = pwg_db_fetch_assoc($result)) { $EAcopyrights[$row['cr_id']] = $row['name']; } $template->assign('EAcopyrights', $EAcopyrights); // Do managing of authors if (isset($_GET['tab'])) { // Create a new author if ($_GET['tab'] == 'create') { // Fetch the values from the form $name = pwg_db_real_escape_string($_REQUEST['name']); $code = pwg_db_real_escape_string($_REQUEST['code']); $url = pwg_db_real_escape_string($_REQUEST['url']); $descr = pwg_db_real_escape_string($_REQUEST['descr']); $copyright = pwg_db_real_escape_string($_REQUEST['copyrightID']); // Check whether an author with such a name or code exists // Therefore count the number of authors with that name or code $query = sprintf( 'SELECT COUNT(*) FROM %s WHERE `name` = \'%s\' OR `code` = \'%s\' ;', AUTHORS, $name, $code); $result = pwg_query($query); $counter = pwg_db_num_rows($result); if ($counter != 0) { // The author exists already array_push($page['errors'], l10n('This author already exists.')); } else { // The author did not yet exist // Compose a query to insert the author $query = sprintf( 'INSERT INTO %s (`name`,`code`,`url`,`descr`,`copyright`) VALUES ("%s","%s","%s","%s",%d) ;', AUTHORS, $name, $code, $url, $descr, $copyright); pwg_query($query); // Execute the query } } // Edit an existing author if ($_GET['tab'] == 'edit') { $edit = 1; // Show the edit page $EAid = $_REQUEST['id']; // Fetch the id of the author to be edited // Fetch the current attributes to the author $query = sprintf( 'SELECT * FROM %s WHERE `author_id`=%d ;', AUTHORS, $EAid); $result = pwg_query($query); $row = pwg_db_fetch_assoc($result); // Save the attributes in convenient variables $EAname = $row['name']; $EAcode = $row['code']; $EAurl = $row['url']; $EAdescr = $row['descr']; $EAcopyright_id = $row['copyright']; } // Update an existing author if ($_GET['tab'] == 'update') { // Fetch the values from the edit form $id = pwg_db_real_escape_string($_REQUEST['id']); $name = pwg_db_real_escape_string($_REQUEST['name']); $code = pwg_db_real_escape_string($_REQUEST['code']); $url = pwg_db_real_escape_string($_REQUEST['url']); $descr = pwg_db_real_escape_string($_REQUEST['descr']); $copyright = pwg_db_real_escape_string($_REQUEST['copyrightID']); // Check whether an author with such a name or code exists // Therefore count the number of authors with that name or code $query = sprintf( 'SELECT COUNT(*) FROM %s WHERE `name` = \'%s\' OR `code` = \'%s\' ;', AUTHORS, $name, $code); $result = pwg_query($query); $counter = pwg_db_num_rows($result); if ($counter != 0) { // The author exists already array_push($page['errors'], l10n('This author already exists.')); } else { // The author did not yet exist // Compose a query to update the author $query = sprintf( 'UPDATE %s SET `name`="%s", `code`="%s", `url`="%s", `descr`="%s", `copyright`=%d WHERE `author_id`=%d ;', AUTHORS, $name, $code, $url, $descr, $copyright, $id); pwg_query($query); // Execute the query } } // Delete an existing author if ($_GET['tab'] == 'delete') { // Fetch the id of the author to be deleted $id = $_REQUEST['id']; // Get the author's name $query = sprintf( 'SELECT name FROM %s WHERE author_id=%d ;', AUTHORS, $id); $result = pwg_query($query); $row = pwg_db_fetch_assoc($result); $name = $row['name']; // Delete all his 'default' entries from the copyright table delete_default_CR($name); // Unset the author in the images table $query = sprintf( 'UPDATE %s SET `author`=NULL WHERE `author`=\'%s\' ;', IMAGES, $name); pwg_query($query); // Delete the author $query = sprintf( 'DELETE FROM %s WHERE `author_id`=%d ;', AUTHORS, $id); pwg_query($query); } } /* Assign variables to the template */ global $template; // Add the admin.tpl template $template->set_filenames( array('plugin_admin_content' => dirname(__FILE__).'/admin.tpl') ); // Select the existing authors $query = sprintf( 'SELECT * FROM %s ;', AUTHORS); $result = pwg_query($query); // Append the authors to the Smarty array while ($row = pwg_db_fetch_assoc($result)) { $template->append( 'EAs', array( 'author_id' => $row['author_id'], 'name' => $row['name'], 'code' => $row['code'], 'url' => $row['url'], 'descr' => $row['descr'], 'copyright_id' => $row['copyright'] ) ); } // Assign the path for URL forming $template->assign( 'E_AUTHOR_PATH', E_AUTHOR_WEB_PATH ); // Assign all the variables we constructed above $template->assign('edit', $edit); $template->assign('EAid', $EAid); $template->assign('EAname', $EAname); $template->assign('EAcode', $EAcode); $template->assign('EAurl', $EAurl); $template->assign('EAdescr', $EAdescr); $template->assign('EAcopyright_id', $EAcopyright_id); // Get it up and running $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); ?>