Example #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;
}
/**
 * Unit Test for DeleteList()
 *
 * @param unknown_type $object
 * @param unknown_type $trace
 */
function TestDeleteList($object, $trace = true)
{
    $className = get_class($object);
    if (!TestSave($object, false) || !TestGetList($object, false)) {
        if ($trace) {
            AddTrace("\tDeleteList() ignored");
        }
        return false;
    }
    $object = PopulateTestValues($object);
    $originalCount = GetNumberOfRecords($className);
    $objectId = false;
    $object->{strtolower($className) . "Id"} = 0;
    $objectId = $object->Save(false);
    $objectId2 = $object->SaveNew(false);
    $objectId3 = $object->SaveNew(false);
    $className = get_class($object);
    $object->DeleteList(array(array(strtolower($className) . "Id", "=", $objectId), array("or"), array(strtolower($className) . "Id", "=", $objectId2), array("or"), array(strtolower($className) . "Id", "=", $objectId3)));
    $newCount = GetNumberOfRecords($className);
    if ($newCount == $originalCount) {
        if ($trace) {
            AddTrace("\tDeleteList()....OK!");
        }
        return true;
    }
    if ($trace) {
        AddTrace("\tDeleteList() failed");
        AddError("Query failed: " . $object->pog_query);
    }
    return false;
}