register(XAJAX_FUNCTION,'ajaxpreview'); $headtext = $xajax->getJavascript('../lib/xajax')."\n"; if (isset($_POST["cancel"])) { redirect("listcontent.php".$urlext); } require_once("header.php"); $tmpfname = ''; $error = FALSE; $submit = false; if (isset($_POST["submitbutton"])) $submit = true; $apply = false; if (isset($_POST["applybutton"])) $apply = true; $contentobj = null; #Get current userid and make sure they have permission to add something $access = (check_permission($userid, 'Add Pages') || check_permission($userid, 'Manage All Content')); #Get a list of content types and pick a default if necessary $gCms = cmsms(); $contentops = $gCms->GetContentOperations(); $existingtypes = $contentops->ListContentTypes(); $content_type = ""; if (isset($_POST["content_type"])) { $content_type = $_POST["content_type"]; } else { if (isset($existingtypes) && count($existingtypes) > 0) { $content_type = get_site_preference('default_contenttype','content'); } else { $error = "No content types loaded!"; } } $contentobj = null; { $page_secure = get_site_preference('page_secure',0); $page_cachable = ((get_site_preference('page_cachable',"1")=="1")?true:false); $active = ((get_site_preference('page_active',"1")=="1")?true:false); $showinmenu = ((get_site_preference('page_showinmenu',"1")=="1")?true:false); $metadata = get_site_preference('page_metadata'); $parent_id = get_preference($userid, 'default_parent', -2); if (isset($_GET["parent_id"])) $parent_id = $_GET["parent_id"]; $contentobj = $contentops->CreateNewContent($content_type); $contentobj->SetAddMode(); $contentobj->SetOwner($userid); $contentobj->SetCachable($page_cachable); $contentobj->SetActive($active); $contentobj->SetShowInMenu($showinmenu); $contentobj->SetLastModifiedBy($userid); $templateops = $gCms->GetTemplateOperations(); $dflt = $templateops->LoadDefaultTemplate(); if( isset($dflt) ) { $contentobj->SetTemplateId($dflt->id); } // this stuff should be changed somehow. $contentobj->SetMetadata($metadata); $contentobj->SetPropertyValue('content_en', get_site_preference('defaultpagecontent')); // why? if ($parent_id!=-1) $contentobj->SetParentId($parent_id); $contentobj->SetPropertyValue('searchable',get_site_preference('page_searchable',1)); $contentobj->SetPropertyValue('extra1',get_site_preference('page_extra1','')); $contentobj->SetPropertyValue('extra2',get_site_preference('page_extra2','')); $contentobj->SetPropertyValue('extra3',get_site_preference('page_extra3','')); $tmp = get_site_preference('additional_editors'); $tmp2 = array(); if( !empty($tmp) ) { $tmp2 = explode(',',$tmp); } $contentobj->SetAdditionalEditors($tmp2); } $xajax->processRequest(); if ($access && strtoupper($_SERVER['REQUEST_METHOD']) == 'POST' ) { try { if ($submit || $apply) { // Fill contentobj with parameters $contentobj->SetAddMode(); $contentobj->FillParams($_POST); $contentobj->SetOwner($userid); $error = $contentobj->ValidateData(); if ($error === FALSE) { $contentobj->Save(); $gCms = cmsms(); $contentops = $gCms->GetContentOperations(); $contentops->SetAllHierarchyPositions(); if ($submit) { // put mention into the admin log audit($contentobj->Id(), 'Content Item: '.$contentobj->Name(), 'Added'); redirect('listcontent.php'.$urlext.'&message=contentadded'); } } } else { $contentobj->FillParams($_POST); } } catch( CmsEditContentException $e) { $error = $e->getMessage(); } } if (!$access) { echo "
".lang('noaccessto',array(lang('addcontent')))."