require_once('assets/libs/docmanager/document.class.inc.php');
$doc = new Document();
$doc->Set('parent',$folder);
$doc->Set('alias','post'.time());
$doc->Set('content','document content');
$doc->Set('template','GuestBookComments');
$doc->Set('tvComment','post to comment');
$doc->Save(); $lastInsertId = $modx->db->getInsertId();
// put the document in the document_groups it should be in
// check that up_perms are switched on!
if($modx->config['use_udperms']==1) {
if(is_array($parentDocGroupsArray)) {
foreach ($parentDocGroupsArray as $dgKey=>$dgValue) {
$insertDocSql = "INSERT INTO ".$modx->getFullTableName('document_groups')."(document_group, document) values(".stripslashes($dgValue).", $lastInsertId)";
$insertDocRs = $modx->db->query($insertDocSql);
if(!$insertDocRs){
exit;
}
} // end foreach
} // end if doc group array exists
} // end if perms are used
// Handle privateweb
$modx->db->query("UPDATE ".$modx->getFullTableName("site_content")." SET privateweb = 0 WHERE id='$lastInsertId';");
$privatewebSql = "
SELECT DISTINCT ".$modx->getFullTableName('document_groups').".document_group
FROM ".$modx->getFullTableName('document_groups').", ".$modx->getFullTableName('webgroup_access')."
WHERE
".$modx->getFullTableName('document_groups').".document_group = ".$modx->getFullTableName('webgroup_access').".documentgroup
AND
".$modx->getFullTableName('document_groups').".document = $lastInsertId;";
$privatewebIds = $modx->db->getColumn("document_group",$privatewebSql);
if(count($privatewebIds)>0) {
$modx->db->query("UPDATE ".$modx->getFullTableName("site_content")." SET privateweb = 1 WHERE id = $lastInsertId;");
}
// And privatemgr
$modx->db->query("UPDATE ".$modx->getFullTableName("site_content")." SET privatemgr = 0 WHERE id='$lastInsertId';");
$privatemgrSql = "
SELECT DISTINCT ".$modx->getFullTableName('document_groups').".document_group
FROM ".$modx->getFullTableName('document_groups').", ".$modx->getFullTableName('membergroup_access')."
WHERE
".$modx->getFullTableName('document_groups').".document_group = ".$modx->getFullTableName('membergroup_access')." .documentgroup
AND
".$modx->getFullTableName('document_groups').".document = $lastInsertId;";
$privatemgrIds = $modx->db->getColumn("document_group",$privatemgrSql);
if(count($privatemgrIds)>0) {
$modx->db->query("UPDATE ".$modx->getFullTableName("site_content")." SET privatemgr = 1 WHERE id = $lastInsertId;");
}
// end of document_groups stuff!
// empty cache
include_once $modx->config['base_path']."manager/processors/cache_sync.class.processor.php";
$sync = new synccache();
$sync->setCachepath("assets/cache/");
$sync->setReport(false);
$sync->emptyCache(); // first empty the cache