Пример #1
0
/**
 * Refreshes the tree after an operation while preserving node statuses
 *
 * @param unknown_type $objectName
 * @param unknown_type $root
 */
function RefreshTree($objectName, $root, $offset = '', $limit = '')
{
    if ($limit == '') {
        $offset = 0;
        $limit = 50;
    }
    $sqlLimit = "{$offset}, {$limit}";
    $js = "new Array(";
    eval('$instance = new ' . $objectName . '();');
    $recCount = GetNumberOfRecords(strtolower($objectName));
    $attributeList = array_keys(get_object_vars($instance));
    $instanceList = $instance->GetList(array(array(strtolower($objectName) . "Id", ">", 0)), strtolower($objectName) . "Id", false, $sqlLimit);
    $x = 0;
    $masterNode =& $root->addItem(new XNode("<span style='color:#998D05'>" . $objectName . "</span>&nbsp;<span style='font-weight:normal'>{Dimensions:[" . sizeof($instanceList) . "]}</span>", false, "setup_images/folderclose.gif", "setup_images/folderopen.gif"));
    $node =& $masterNode->addItem(new XNode("<span style='color:#998D05'>ADD RECORD</span>", false, "setup_images/folderclose.gif", "setup_images/folderopen.gif"));
    foreach ($attributeList as $attribute) {
        if ($attribute != "pog_attribute_type" && $attribute != "pog_query") {
            if ($x != 0 && isset($instance->pog_attribute_type[$attribute])) {
                $js .= '"' . $attribute . '",';
                $thisValue = ConvertAttributeToHtml($attribute, $instance->pog_attribute_type[$attribute]['db_attributes'], $instance->{$attribute}, $instance->{$attributeList[0]});
                $subnode =& $node->addItem(new XNode("<br/><span style='color:#998D05'>" . $attribute . "</span>&nbsp;<span style='font-weight:normal;color:#ADA8B2;'>{" . $instance->pog_attribute_type[$attribute]['db_attributes'][1] . "}</span><br/>" . $thisValue . "<br/>", false, '', "setup_images/folderopen.gif"));
            }
        }
        $x++;
    }
    $js = trim($js, ",");
    $js .= ")";
    $subnode =& $node->addItem(new XNode("<br/><a href='#' onclick='javascript:sndReq(\"Add\", getOpenNodes(), \"{$objectName}\", \"" . $instance->{strtolower($objectName) . 'Id'} . "\", this.parentNode.parentNode.parentNode.parentNode.id, {$js}, \"{$objectName}\");return false;'><img src='./setup_images/button_add.gif' border='0'/></a>", false, '', "folderopen.gif"));
    if ($instanceList != null) {
        foreach ($instanceList as $instance) {
            ConvertObjectToNode($instance, $masterNode, $js, $objectName);
        }
    }
    $menu_html_code = $root->generateTree();
    $menu_html_code .= "<div class='nav'>";
    $pre = "<div class='nav'>";
    if ($offset != '' && $offset != 0) {
        $pre .= "&#8249;&#8249;<a href='#' onclick='javascript:refTree(" . ($offset - $limit) . ", {$limit}, \"{$objectName}\");return false;'>Newer</a> | ";
        $menu_html_code .= "&#8249;&#8249;<a href='#' onclick='javascript:refTree(" . ($offset - $limit) . ", {$limit}, \"{$objectName}\");return false;'>Newer</a> | ";
    }
    $pre .= "<b>" . ($recCount - $offset - $limit < 0 ? 0 : $recCount - $offset - $limit) . " - " . ($recCount - $offset) . " of {$recCount} </b>";
    $menu_html_code .= "<b>" . ($recCount - $offset - $limit < 0 ? 0 : $recCount - $offset - $limit) . " - " . ($recCount - $offset) . " of {$recCount} </b>";
    if ($offset <= $recCount - $limit) {
        $pre .= "| <a href='#' onclick='javascript:refTree(" . ($offset + $limit) . ", {$limit}, \"{$objectName}\");return false;'>Older</a>&#8250;&#8250;";
        $menu_html_code .= "| <a href='#' onclick='javascript:refTree(" . ($offset + $limit) . ", {$limit}, \"{$objectName}\");return false;'>Older</a>&#8250;&#8250;";
    }
    $menu_html_code .= "</div>";
    $pre .= "</div>";
    $table = "<div id='container'><br/><br/>" . $pre . $menu_html_code . "</div>";
    echo $table;
}
Пример #2
0
/**
 * Renders an object as an Xtree Node
 *
 * @param unknown_type $child
 */
function ConvertObjectToNode(&$instance, &$masterNode, $js, $anchor, $once = false)
{
    $attributeList = array_keys(get_object_vars($instance));
    $objectName = $className = get_class($instance);
    $node =& $masterNode->addItem(new XNode("<span style='color:#0BAA9D'>[" . $instance->{strtolower($className) . "Id"} . "]</span>  <a href='#' onclick='ToggleElementVisibility(\"deleteConfirm_" . $instance->{strtolower($objectName) . 'Id'} . "\");return false;'><img src=\"./setup_images/button_delete.gif\" border=\"0\"/></a> <span id='deleteConfirm_" . $instance->{strtolower($objectName) . 'Id'} . "' style='display:none;width:250px;'><a href='#' class='deleteDeep' onclick='javascript:sndReq(\"DeleteDeep\", getOpenNodes(), \"{$objectName}\", \"" . $instance->{strtolower($objectName) . 'Id'} . "\", this.parentNode.parentNode.parentNode.parentNode.id, {$js}, \"{$anchor}\");return false;'>Delete(deep)</a> | <a href='#' class='deleteShallow' onclick='javascript:sndReq(\"Delete\", getOpenNodes(), \"{$objectName}\", \"" . $instance->{strtolower($objectName) . 'Id'} . "\", this.parentNode.parentNode.parentNode.parentNode.id, {$js}, \"{$anchor}\");return false;'>Delete(shallow)</a> | <a href='#' class='deleteCancel' onclick='ToggleElementVisibility(\"deleteConfirm_" . $instance->{strtolower($objectName) . 'Id'} . "\");return false;'>Cancel</a></span>", false, "setup_images/folderclose.gif", "setup_images/folderopen.gif"));
    //regular attributes
    foreach ($attributeList as $attribute) {
        if ($attribute != "pog_attribute_type" && $attribute != "pog_query") {
            if (isset($instance->pog_attribute_type[$attribute])) {
                $thisValue = ConvertAttributeToHtml($attribute, $instance->pog_attribute_type[$attribute]['db_attributes'], $instance->{$attribute}, $instance->{$attributeList[0]});
                $subnode =& $node->addItem(new XNode("<br/>" . $attribute . "<span style='font-weight:normal;color:#ADA8B2;'>{" . $instance->pog_attribute_type[$attribute]['db_attributes'][1] . "}</span><br/>" . str_replace("", "", $thisValue) . "<br/><br/>", false, '', "setup_images/folderopen.gif"));
            }
        }
    }
    //parents, children and mapping
    foreach ($instance->pog_attribute_type as $attribute_name => $attrubute_type) {
        if ($attrubute_type['db_attributes'][1] == "HASMANY" || $attrubute_type['db_attributes'][1] == "BELONGSTO" || $attrubute_type['db_attributes'][1] == "JOIN") {
            if ($attrubute_type['db_attributes'][1] == "BELONGSTO") {
                eval('$value = $instance->' . strtolower($attribute_name) . 'Id;');
                $thisValue = ConvertAttributeToHtml($attribute_name, $attrubute_type['db_attributes'], $value, '');
                $subnode =& $node->addItem(new XNode("<br/>" . $attribute_name . "<span style='font-weight:normal;color:#ADA8B2;'>{" . ($attrubute_type['db_attributes'][1] == "HASMANY" ? "CHILD" : "PARENT") . "}</span><br/>" . $thisValue . "<br/><br/>", false, '', "setup_images/folderopen.gif"));
            } else {
                $value = '';
                eval('$siblingList = $instance->Get' . ucfirst(strtolower($attribute_name)) . 'List();');
                if (sizeof($siblingList) > 0) {
                    $myNode =& $node->addItem(new XNode("<span style='color:#4d4a4a'>[" . $attribute_name . "List]{Dimensions:[" . sizeof($siblingList) . "]}</span>", false, "setup_images/folderclose.gif", "setup_images/folderopen.gif", true));
                    $child = $siblingList[0];
                    $js2 = "new Array(";
                    $attributeList = array_keys(get_object_vars($child));
                    $x = 0;
                    foreach ($attributeList as $attribute) {
                        if ($attribute != "pog_attribute_type" && $attribute != "pog_query") {
                            if ($x != 0 && isset($child->pog_attribute_type[$attribute])) {
                                $js2 .= '"' . $attribute . '",';
                            }
                        }
                        $x++;
                    }
                    $js2 = trim($js2, ",");
                    $js2 .= ")";
                    if (!$once) {
                        foreach ($siblingList as $child) {
                            /*$value .= $child->{strtolower($attribute_name)."Id"} . ",";*/
                            if ($attrubute_type['db_attributes'][1] == "JOIN") {
                                ConvertObjectToNode($child, $myNode, $js2, $anchor, true);
                            } else {
                                ConvertObjectToNode($child, $myNode, $js2, $anchor);
                            }
                        }
                    }
                } else {
                    $node->addItem(new XNode("<span style='color:#4d4a4a'>[" . $attribute_name . "List]{Dimensions:[0]}</span><br/><br/>", false, '', "setup_images/folderopen.gif"));
                }
            }
        }
    }
    $subnode =& $node->addItem(new XNode("<br/><a style='float:left;' href='#' onclick='javascript:PleaseWait(\"" . $instance->{strtolower($objectName) . 'Id'} . "\"); sndReq(\"Update\", getOpenNodes(), \"{$objectName}\", \"" . $instance->{strtolower($objectName) . 'Id'} . "\", this.parentNode.parentNode.parentNode.parentNode.id, {$js}, \"{$anchor}\");return false;'><img src='./setup_images/button_update.gif' border='0'/></a><span id='pleasewait" . $instance->{strtolower($objectName) . 'Id'} . "' style='float:left;display:none;'><img src='./setup_images/loading.gif' style='float:left;'/></span><br/>", false, '', "folderopen.gif"));
}