".__('Folders:')."\n" ."
\n"; echo "
\n"; echo "

\n"; echo "\n" ."" ."\n" ."\n" ."

\n\n"; echo "\n" ."\n" ."\t\n"; if (getConfig('rss.config.absoluteordering')) { echo "\t\n"; } echo "\t\n" ."\n"; $sql = "select id,name from " .getTable("folders"); if (getConfig('rss.config.absoluteordering')) { $sql .=" order by position asc"; } else { $sql .=" order by name asc"; } $res = rss_query($sql); $cntr = 0; while (list($id, $name) = rss_fetch_row($res)) { $name = $name == ''? __('Root'):$name; $class_ = (($cntr++ % 2 == 0)?"even":"odd"); echo "\n" ."\t\n"; if (getConfig('rss.config.absoluteordering')) { echo "\t\n"; } echo "\t\n" ."\n"; } echo "
". __('Title') ."".__('Move')."". __('Action') ."
$name"; if ($id > 0) { if ($cntr > 2) { echo "". __('↑') ." - "; } echo "".__('↓') .""; } else { echo " "; } echo "" . __('edit') .""; if ($id > 0) { echo "|" . __('delete') .""; } echo "
"; echo "
\n"; } function folder_edit($fid) { $sql = "select id, name from " . getTable("folders") ." where id=$fid"; $res = rss_query($sql); list ($id, $name) = rss_fetch_row($res); echo "
\n"; echo "\n\n

Edit '$name'

\n"; echo "
\n" ."

\n" ."\n" ."\n" // Item name ."\n" ."

"; echo "

" ."
\n"; } function folder_admin() { // Fix for #16: Admin (et al.) should not rely on l10n labels for actions: // Look for a meta-action first, which should be the (untranslated) *name* of // the (translated) action constant. // Fixme: should replace 'action's with a constant if (array_key_exists(CST_ADMIN_METAACTION,$_REQUEST)) { $__action__ = $_REQUEST[CST_ADMIN_METAACTION]; } elseif (array_key_exists('action',$_REQUEST)) { $__action__ = $_REQUEST['action']; } else { $__action__ = ""; } if (isset($_REQUEST['fid'])) { $fid = sanitize($_REQUEST['fid'],RSS_SANITIZER_NUMERIC); } $ret__ = CST_ADMIN_DOMAIN_FOLDER; switch ($__action__) { case CST_ADMIN_EDIT_ACTION: folder_edit($fid); $ret__ = CST_ADMIN_DOMAIN_NONE; break; case CST_ADMIN_DELETE_ACTION: if ($fid == 0) { rss_error(__("You can't delete the Root folder"), RSS_ERROR_ERROR,true); break; } if (array_key_exists(CST_ADMIN_CONFIRMED,$_POST) && $_POST[CST_ADMIN_CONFIRMED] == __('Yes')) { $sql = "delete from " . getTable("folders") ." where id=$fid"; rss_query($sql); $sql = "update " . getTable("channels") ." set parent=" . getRootFolder() . " where parent=$fid"; rss_query($sql); rss_invalidate_cache(); } elseif (array_key_exists(CST_ADMIN_CONFIRMED,$_REQUEST) && $_REQUEST[CST_ADMIN_CONFIRMED] == __('No')) { // nop; } else { list($fname) = rss_fetch_row(rss_query("select name from " .getTable("folders") ." where id = $fid")); echo "
\n" ."

"; printf(__("Are you sure you wish to delete '%s'?"),$fname); echo "

\n" ."

\n" ."\n" ."\n" ."\n" ."\n" ."

\n
\n"; $ret__ = CST_ADMIN_DOMAIN_NONE; } break; case CST_ADMIN_SUBMIT_EDIT: // TBD $new_label = sanitize($_REQUEST['f_name'], RSS_SANITIZER_URL); $new_label = rss_real_escape_string($new_label); if (is_numeric($fid) && strlen($new_label) > 0) { $res = rss_query("select count(*) as cnt from " . getTable("folders") ." where binary name='$new_label'"); list($cnt) = rss_fetch_row($res); if ($cnt > 0) { rss_error(sprintf(__("You can't rename this item '%s' because such an item already exists."),$new_label), RSS_ERROR_ERROR,true); break; } rss_query("update " .getTable("folders") ." set name='$new_label' where id=$fid"); rss_invalidate_cache(); } break; case __('Add'): case 'ACT_ADMIN_ADD': $label=sanitize($_REQUEST['new_folder'],RSS_SANITIZER_URL); $new_label = rss_real_escape_string($new_label); assert(strlen($label) > 0); create_folder($label); break; case CST_ADMIN_MOVE_UP_ACTION: case CST_ADMIN_MOVE_DOWN_ACTION: if ($fid == 0) { return; } $res = rss_query("select position from " .getTable("folders") ." where id=$fid"); list($position) = rss_fetch_row($res); $sql = "select id, position from " .getTable("folders") ." where id != $fid order by abs($position-position) limit 2"; $res = rss_query($sql); // Let's look for a lower/higher position than the one we got. $switch_with_position=$position; while (list($oid,$oposition) = rss_fetch_row($res)) { if ( // found none yet? ($switch_with_position == $position) && ( // move up: we look for a lower position ($_REQUEST['action'] == CST_ADMIN_MOVE_UP_ACTION && $oposition < $switch_with_position) || // move up: we look for a higher position ($_REQUEST['action'] == CST_ADMIN_MOVE_DOWN_ACTION && $oposition > $switch_with_position) ) ) { $switch_with_position = $oposition; $switch_with_id = $oid; } } // right, lets! if ($switch_with_position != $position) { rss_query( "update " . getTable("folders") ." set position = $switch_with_position where id=$fid" ); rss_query( "update " . getTable("folders") ." set position = $position where id=$switch_with_id" ); rss_invalidate_cache(); } break; default: break; } return $ret__; } /** * Creates a folder with the given name. Does some sanity check, * creates the folder, then returns the */ function create_folder($label, $complainonerror=true) { $res = rss_query ("select count(*) from " .getTable("folders") ." where name='" .rss_real_escape_string($label). "'"); list($exists) = rss_fetch_row($res); if ($exists > 0 && $complainonerror) { rss_error(sprintf(__("Looks like you already have a folder called '%s'!"), $label), RSS_ERROR_ERROR,true); return; } elseif ($exists == 0) { $res = rss_query("select 1+max(position) as np from " . getTable("folders")); list($np) = rss_fetch_row($res); if (!$np) { $np = "0"; } rss_query("insert into " .getTable("folders") ." (name,position) values ('" . rss_real_escape_string($label) ."', $np)"); rss_invalidate_cache(); } list($fid) = rss_fetch_row( rss_query("select id from " .getTable("folders") ." where name='". rss_real_escape_string($label) ."'")); return $fid; } ?>