<?php use_helper('Javascript','Object', 'tvtl', 'ModalBox'); ?>
<h3>Chọn thư mục cho thành viên <?php echo $fullname ?> quản trị</h3>
<div id="checkall" class="span-2"></div>
<div id="uncheckall"></div>
<div style="height:10px"></div>
    <div id="folderTree" style="height:350px; overflow:auto;"></div>
    <div style="height:10px"></div>
    <div class="span-2"><input type="button" value=" Cập nhật " onclick="getCat();"></div>
    <div><input type="button"  value="Đóng cửa sổ" onclick="Modalbox.hide()"></div>
    <div id="result">&nbsp;</div><br>

<?php $sf_context->getResponse()->addJavascriptCommand('
tree=new dhtmlXTreeObject("folderTree","100%","auto",0);
tree.setImagePath("/plugins/dhtmlx/images/");
tree.enableDragAndDrop(false);
tree.enableCheckBoxes(true);
tree.loadXMLString("'.blogStore::$catTree->getTree(null, '/./', true, true).'");
tree.openItem("root");
var str = "'.$cat_exist.'";
var catCurrents = str.split(",");

for(var i = 0; i < catCurrents.length; i++) {
  tree.openItem("tr"+catCurrents[i]);
  tree.setCheck("tr"+catCurrents[i],1);
}
showLink();

getCat = function() {
  var cats = tree.getAllChecked();
  cats = cats.replace(/tr/g,"");
  $("result").innerHTML = "";
  new Ajax.Updater("result",
    "'.url_for("/admin/managefolder?user_id=$user_id").'/cat_id/" + cats,
    {asynchronous:false, evalScripts:false});
  return $("result").innerHTML == "Bạn đã cập nhật thành công";
}

function showLink() {
  $("checkall").innerHTML = "<a href=\'#\' onclick=\'tree.setSubChecked(\\"root\\",1);\' >Chọn tất cả</a>";
  $("uncheckall").innerHTML = "<a href=\'#\' onclick=\"tree.setSubChecked(\\"root\\",0);\'; >Bỏ tất cả</a>";
}
'); ?>