Ejemplo n.º 1
0
function document_process ($root_table, $root_id, $root_template)
{
    global $scanner, $dep, $db, $path_tail, $current_index, $current_indices, $default_document, $document_template, $debug, $list_offsets, $url_vars;

    list ($dirtype, $table, $id, $vdir, $path_tail, $name) = document_path_to_directory (explode ('/', $_SERVER['PATH_INFO']), $root_table, $root_id);

    # Check if the first unprocessed directory of the tail is a known
    # object class and use it as the template. If it's not, a default template
    # is used.
    $template = '';
    if (sizeof ($path_tail) > 0)
        if ($db->select ('id', 'obj_classes', 'name=\'' . $path_tail[0] . '\''))
            $template = $path_tail[0]; # Tail is a legal user template.
    if (!$template)
        if ($table == $root_table && $id == $root_id && !$vdir)
	    $template = $root_template;	# Show index page.
        else
	    $template = $default_document[$dirtype]; # Use default template.

    # Fetch document template for this directory.
    # Don't use cms_fetch_object() here because there's no cursor.
    $dbobj = new DBOBJ ($db, $template, $dep, $table, $id, true);

    # Export public object as file.
    # This is done right here to skip all other activities and exit.
    if ($name == 'OBJ') {
        if (!is_array ($dbobj->active) || !$dbobj->active['id'])
	    die ("'$template' is not an object class.");
        if (!$dbobj->active['is_public'])
	    panic ('Object is not marked public!');
        Header ('Content-type: ' . $dbobj['mime']);
        echo $dbobj->active['data']; # No run through scanner.
        exit;
    }

    if (!isset ($dbobj->active['data']))
        die ('Kein Dokument für die Eingansseite definiert - stop.');
    $document_template = $dbobj->active['data'];

    # Get index info.
    $tmp = $table;
    $rid = $id;
    dbitree_get_parent ($db, $tmp, $rid);
    if (!$tmp)
        die ('No such path.');

    # Fetch result into array.
    for ($res = dbitree_get_children ($db, $table, $rid);
	 $tmp = $res->get ();
	 $set[$tmp['id_last']] = $tmp['id']);

    # Sort indices into $current_indices array and find the current one.
    for ($i = 1, $last = 0; isset ($set[$last]) && ($rid = $current_indices[$i] = $set[$last]); $last = $rid, $i++)
        if ($rid == $id)
	    $current_index = $i;

    # Feed list offsets into URL vars.
    if (isset ($list_offsets))
        foreach ($list_offsets as $key => $val)
            $url_vars["list_offsets[$key]"] = $val;

    # Open a new context.
    $scanner->push_context (); # XXX is this really required?
    cms_create_context ($dirtype, $table, $id);

    # Call document handler if the current directory is virtual.
    if ($vdir) {
        # Explicitly create context for virtual directory.

        # Call document handler.
        # TODO: Document handlers for any directory type.
        $func = 'document_' . strtolower ($dirtype);
        $func ();
    }

    if ($debug)
        echo "dirtype: $dirtype - tab: $table - id: $id - default template: $template<br>";

    # Invoke scanner and evaluate the page.
    # TODO: This could depend on the document template's mime type.
    # see also the scanner in lib/scanner.class.
    $document_tree = $scanner->scan ($document_template);
    $out = $scanner->exec ($document_tree, $table, $id);
    eval ("?>$out<?");
}
Ejemplo n.º 2
0
function edit_data_navigator(&$app)
{
    global $lang;
    $p =& $app->ui;
    $dep =& $app->db->def;
    $class = $app->arg('class');
    $table = $app->arg('table');
    $id = $app->arg('id');
    $otable = $app->arg('otable');
    $oid = $app->arg('oid');
    $p->link($lang['cmd defaultview'], 'defaultview');
    show_directory_index($app, $otable, $oid, true);
    $p->link($lang['cmd back/quit'], 'return2caller');
    $p->headline($lang['available objects']);
    $xtable = $otable;
    $xid = $oid;
    echo '<table border="0">';
    do {
        $obj = new DBOBJ($app->db, $class, $dep, $xtable, $xid);
        if (!isset($obj->data)) {
            break;
        }
        # Get source directory of the found object.
        $t = $obj->data['_table'];
        $i = $obj->data['_id'];
        # Mark the path if the object is currently displayed.
        if ($t == $table && $i == $id) {
            echo '<td><b>' . $lang['current'] . '</b></td><td>-</td>';
        } else {
            echo '<td>&nbsp;</td><td>';
            $e = new event('copy_object', array('class' => $class, 'table' => $otable, 'id' => $oid, 'srctable' => $obj->data['_table'], 'srcid' => $obj->data['_id']));
            $e->set_next($app->event());
            $p->link($lang['copy to current'], $e);
            echo '</td>';
        }
        # Print the path to the directory.
        echo '<td>';
        $p->link($app->db->traverse_refs_from($app, $t, $i, 'nav_linkpath', false, false), new event('edit_data', array('table' => $t, 'id' => $i, 'class' => $class, 'otable' => $otable, 'oid' => $oid)));
        echo '</td></tr>';
        # Fetch parent directory's position and break if there is none.
        $xtable = $t;
        $xid = $i;
        dbitree_get_parent($app->db, $xtable, $xid);
    } while ($xid);
    echo '</table>';
}