Exemple #1
0
 function NWNSettings($name, $properties = null)
 {
     parent::DataTreeObject($name);
     // dto settings
     $this->data['type'] = 'nwnsettings';
     $this->data['name'] = isset($properties['name']) ? $properties['name'] : '';
     // datatree initialization for persistent storage
     global $conf;
     $driver = $conf['datatree']['driver'];
     $params = Horde::getDriverConfig('datatree', $driver);
     $params = array_merge($params, array('group' => 'nwnadmin.settings'));
     $this->_datatree =& DataTree::singleton($driver, $params);
     // create the neccessary datatree node if it does not exist
     if (!$this->_datatree->exists($this)) {
         $this->_datatree->add($this);
     }
 }
 public function anyDatatree()
 {
     if (!class_exists('\\Baum\\Node')) {
         die("You need to install Baum\\Baum and repopulate the database to use the DataTree");
     }
     // for demo purposes only, ensure the root exists
     $root = Menu::firstOrNew(['id' => 1]);
     $root->save();
     // load the root model
     $root = Menu::find(1) or App::abort(404);
     $tree = \DataTree::source($root);
     $tree->add('title');
     $tree->edit("/rapyd-demo/menuedit", 'Edit', 'modify|delete');
     $tree->submit('Save the order');
     return view('rapyd::demo.tree', compact('tree'));
 }
 public static function isMainType($type_id)
 {
     if (!is_numeric($type_id)) {
         return array('0' => false, 'message' => "参数应为整型");
     }
     $tree = DataTree::getInstance();
     $result = $tree->getANodeByOtherNode($type_id, 1);
     if ($result[0]) {
         //查找成功
         $node = $result[1];
         // $root=$tree->getOneTreeNode();
         $maintype = self::getMainTypeId();
         if ($maintype[0]) {
             $maintype_id = $maintype[1];
         } else {
             return array('0' => false, 'message' => "未查找到主分类id");
         }
         if ($node->type_id == $maintype_id) {
             return array('0' => true, 'ismaintype' => true);
         } else {
             return array('0' => true, 'ismaintype' => false);
         }
     } else {
         return array('0' => false, 'message' => "查找祖先节点失败");
     }
 }
/**
 *
 *  excellent_setting.inc.php 2016-1-5 龚成
 */
if (!defined('IN_DISCUZ')) {
    exit('Access Denied');
}
if (defined('DISCUZ_ROOT')) {
    $path = DISCUZ_ROOT . "source\\plugin\\excellent_shared\\";
}
require_once $path . "class/DiscuzDataTree.class.php";
require_once $path . "function/function_makeCache.php";
require_once "class/TypeArray.class.php";
//require_once ("class/CenterGradation.class.php");
$tree = DataTree::getInstance();
echo "josn_menu:" . $tree->getOneTreeNodeJson() . "<br/>";
$new_json = <<<EOT
\t\t{\t"father_type_id":null,
\t\t\t"type_id":"37",
\t\t\t"type_name":"root",
\t\t\t"type_level":0,
\t\t\t"child_type_id":{
\t\t\t\t"0":"65535",
\t\t\t\t"1":"65535"
\t\t\t},
\t\t\t"child":{
\t\t\t\t"0":{
\t\t\t\t\t"father_type_id":"37",
\t\t\t\t\t"type_id":"65535",
\t\t\t\t\t"type_name":"gongcheng",
 public static function insertThreadTypeSFun($tid, $type_id, $rate)
 {
     //参数检查
     if (empty($tid) || !is_array($type_id) || empty($type_id)) {
         echo "参数错误<br/>";
         return false;
     }
     //检查评论项,更改其格式(为空则置NULL,为str则加上单引号)
     if ($rate == NULL || !is_string($rate)) {
         $rate = "NULL";
     } else {
         $rate = "'{$rate}'";
     }
     //获取type的level,构造type数组(type_id=>type_level)
     $type = ThreadWithType::getTypeSFun($type_id);
     if (!$type) {
         echo "请检查type_id参数";
         return false;
     }
     //获取其数据库操作对象
     $db = GCDB::getInstance();
     //检查数据库是否已经存在该分类
     $sql = "";
     foreach ($type_id as $key => $value) {
         $sql = "SELECT count(*) as 'num' FROM `{$db->tablepre}forum_gc_excellent_thread` WHERE tid={$tid} AND type_id={$value};";
         $sqldata = $db->query($sql);
         $row = $sqldata->fetch_assoc();
         if ($row['num'] > 0) {
             //说明已存在该类关系,则去掉数组值
             unset($type_id[$key]);
             unset($type[$value]);
         }
     }
     if (empty($type)) {
         echo "{__LINE__}:该分类关系已经存在<br/>";
         return true;
     }
     //上面函数已经检查好参数
     //先进行数据库查重
     //构造sql语句
     //开始事务
     $db->start_transaction();
     //数据库查重
     foreach ($type as $id => $level) {
         $sql = "DELETE FROM `{$db->tablepre}forum_gc_excellent_thread` WHERE tid={$tid} AND ( 0 ";
         //此处加空格,直接删除同类型的tid联系
         if ($level < 30) {
             //是树节点,需要查找其所有的子节点,看是否有重复
             $tree = DataTree::getInstance();
             //获取其所有子节点id
             //参数为空则是获取所有节点
             $childid_array = $tree->getOneTreeNodeAllTypeid();
             foreach ($childid_array as $value) {
                 $sql .= " OR type_id={$value} ";
             }
         } else {
             //是多重分类,则按照每一层进行查找
             $leveltype = TypeArray::getInstance();
             $brotherid = $leveltype->getArrayTypeid($level);
             if (!$brotherid) {
                 //返回错误
                 echo "{__LINE__}:无法获取同类多重类型id<br/>";
                 return false;
             }
             foreach ($brotherid as $value) {
                 $sql .= " OR type_id={$value} ";
             }
         }
         $sql .= ");";
         echo "{__LINE__}:sql:" . $sql . "<br/>";
         //执行sql语句
         if (!$db->query($sql)) {
             echo "数据库除重失败!<br/>";
             //事务回滚
             $db->rollback_transaction();
             return false;
         }
     }
     //插入数据库
     $sql = "INSERT INTO `{$db->tablepre}forum_gc_excellent_thread`(`tid`,`type_id`,`rate`) VALUES ";
     foreach ($type_id as $value) {
         $sql .= "({$tid},{$value},{$rate}),";
     }
     //sql语句去掉最后一个逗号,并加上分号
     $sql = substr($sql, 0, -1);
     $sql .= ";";
     echo "{__LINE__}:INSERT:{$sql}<br/>";
     //运行sql语句
     if (!$db->query($sql)) {
         echo "插入操作失败<br/>";
         $db->rollback_transaction();
         return false;
     }
     //提交事务
     $db->commit_transaction();
     //返回
     return true;
 }
Exemple #6
0
    $form->addVariable(_("No child permissions are to be added below this level."), 'child', 'description', false);
} elseif (is_array($child_perms)) {
    /* Choice array available, so set up enum field. */
    $form->addVariable(_("Permission"), 'child', 'enum', true, false, null, array($child_perms));
} else {
    /* No choices returned, so give a free form text field. */
    $form->addVariable(_("Permission"), 'child', 'text', true);
}
if ($form->validate($vars)) {
    $form->getInfo($vars, $info);
    if ($info['cid'] == '-1') {
        $child =& $perms->newPermission($info['child']);
        $result = $perms->addPermission($child);
    } else {
        $pOb =& $perms->getPermissionById($info['cid']);
        $name = $pOb->getName() . ':' . DataTree::encodeName($info['child']);
        $child =& $perms->newPermission($name);
        $result = $perms->addPermission($child);
    }
    if (is_a($result, 'PEAR_Error')) {
        $notification->push(sprintf(_("'%s' was not created: %s."), $child->getShortName(), $result->getMessage()), 'horde.error');
    } else {
        $notification->push(sprintf(_("'%s' was added to the permissions system."), $child->getShortName()), 'horde.success');
        $permission =& $child;
        $url = Horde::applicationUrl('admin/perms/edit.php', true);
        $url = Util::addParameter($url, 'cid', $permission->getId());
        header('Location: ' . $url);
        exit;
    }
}
$title = _("Permissions Administration");
        $categoryOb =& new DataTreeObject_Group($name);
        $categoryOb->data = $category->getCategoryData($id);
        if ($live) {
            $result = $category->updateData($categoryOb);
            if (is_a($result, 'PEAR_Error')) {
                var_dump($result);
                exit;
            }
        }
    }
}
// Shares.
if ($shares) {
    $category =& DataTree::factory('sql');
    $db =& $category->_db;
    $ids = $db->getAssoc('SELECT category_id, category_name, group_uid FROM horde_categories WHERE group_uid LIKE \'horde.shares.%\'');
    foreach ($ids as $id => $row) {
        $category = DataTree::factory('sql');
        $category->_params['group'] = $row[1];
        $category->_load();
        $categoryOb =& new DataTreeObject_Share($row[0]);
        $categoryOb->data = $category->getCategoryData($id);
        if ($live) {
            $result = $category->updateData($categoryOb);
            if (is_a($result, 'PEAR_Error')) {
                var_dump($result);
                exit;
            }
        }
    }
}
 /**
 +----------------------------------------------------------
 * 取得数据库类实例
 +----------------------------------------------------------
 * @static
 * @access public
 +----------------------------------------------------------
 * @return mixed 返回数据库驱动类
 +----------------------------------------------------------
 */
 public static function getInstance()
 {
     if (self::$_instance == null) {
         self::$_instance = new DataTree();
     }
     return self::$_instance;
 }
Exemple #9
0
$spacer = '&nbsp;&nbsp;&nbsp;&nbsp;';
$current = Util::getFormData('cid');
$icondir = array('icondir' => $registry->getParam('graphics'));
$group_node = $icondir + array('icon' => 'group.gif');
$add = Horde::applicationUrl('admin/groups.php?actionID=addchild');
$edit = Horde::applicationUrl('admin/groups.php?actionID=edit');
$delete = Horde::applicationUrl('admin/groups.php?actionID=delete');
$edit_img = Horde::img('edit.gif', _("Edit Group"), 'hspace="2"');
$delete_img = Horde::img('delete.gif', _("Delete Group"), 'hspace="2"');
/* Set up the tree. */
$tree =& Horde_Tree::singleton('datatree', 'javascript');
$tree->setOption(array('border' => '0', 'class' => 'item', 'cellpadding' => '0', 'cellspacing' => '0', 'alternate' => true));
foreach ($nodes as $cid => $node) {
    $node_class = $current == $cid ? array('class' => 'selected') : array();
    if ($cid == -1) {
        $add_img = Horde::img('group.gif', _("Add New Group"), 'hspace="2"');
        $add_link = Horde::link(Util::addParameter($add, 'cid', $cid), _("Add New Group")) . $add_img . '</a>';
        $base_node_params = $icondir + array('icon' => 'administration.gif');
        $tree->addNode($cid, null, _("All Groups"), 0, true, $base_node_params + $node_class, array($spacer, $add_link));
    } else {
        $add_img = Horde::img('group.gif', _("Add Child Group"), 'hspace="2"');
        $add_link = Horde::link(Util::addParameter($add, 'cid', $cid), _("Add Child Group")) . $add_img . '</a>';
        $edit_link = Horde::link(Util::addParameter($edit, 'cid', $cid), _("Edit Group")) . $edit_img . '</a>';
        $delete_link = Horde::link(Util::addParameter($delete, 'cid', $cid), _("Delete Group")) . $delete_img . '</a>';
        $parent_id = $groups->_datatree->getParent($node);
        $group_extra = array($spacer, $add_link, $edit_link, $delete_link);
        $tree->addNode($cid, $parent_id, DataTree::getShortName($node), substr_count($node, ':') + 1, false, $group_node + $node_class, $group_extra);
    }
}
$tree->renderTree();
require HORDE_TEMPLATES . '/common-footer.inc';
 public static function beCategoried($tid)
 {
     //若参数不是数字,则报错
     if (!is_numeric($tid)) {
         //echo "参数错误<br/>";
         return array(intval(-1), "参数错误");
     }
     //查找数据库
     $db = GCDB::getInstance();
     $sql = "SELECT type_id,rate FROM `{$db->tablepre}forum_gc_excellent_thread` WHERE tid={$tid};";
     //echo "sql:{$sql}";
     $sqldata = $db->query($sql);
     if (!$sqldata) {
         //echo "查询数据库出错<br/>";
         return array(intval(-1), "数据库查询错误sql:" . $sql);
     }
     $row = $sqldata->fetch_assoc();
     if (empty($row)) {
         //没有分类
         return array(false, "未找到该分类");
     }
     //已分类
     $tree = DataTree::getInstance();
     $type_array = array();
     $type_array[0] = array();
     $type_array[0]['type_id'] = $row['type_id'];
     $type_array[0]['rate'] = $row['rate'];
     $type_array[0]['type_name'] = $tree->getOneTreeNode($row['type_id'])->type_name;
     $i = 1;
     while ($row = $sqldata->fetch_assoc()) {
         $type_array[$i]['type_id'] = $row['type_id'];
         $type_array[$i]['rate'] = $row['rate'];
         $type_array[$i]['type_name'] = $tree->getOneTreeNode($row['type_id'])->type_name;
         $i += 1;
     }
     return array(true, $type_array);
 }
if (!defined('IN_DISCUZ')) {
    exit('Access Denied');
}
if ($_G[uid] == 0) {
    //showmessage('not_loggedin', null, 'NOPERM');
    showmessage('请选登录', '', array(), array('login' => true));
}
require_once "class/DiscuzDataTree.class.php";
require_once "class/TypeArray.class.php";
//获取type_id数组,如果未给出type_id数组,则直接获取根节点id
require_once "class/ThreadWithType.class.php";
require_once "function/function_showThreadWithTable.php";
require_once "function/function_showAttachmentDownload.php";
require_once "function/function_getAttachType.php";
require_once "function/function_showSearchTPL.php";
//获取分类下的帖子
$type_id = $_POST[type_id];
//print_r(ThreadWithType::beCategoried(1));
$datatree = $datatree = DataTree::getInstance();
//获取所有分类对象
$data_array = $datatree->getDataArray();
showSearchTPL($data_array);
if (empty($type_id)) {
    $type_id = array();
    $type_id[] = $datatree->getOneTreeNode()->type_id;
    //获取根节点的type_id
}
$result = ThreadWithType::getThreadSFun($type_id)[1];
//第二个参数为显示风格,0为panel显示风格,1为table显示风格
showThreadWithTable($result, 0);