HasSystemPermission("SYSTEM_ACCESS.READONLY"); require_login( !admin_login() && $Action, 'expired=1', true ); // permission checking: begin $action_mapping = Array( 'n_article_delete' => 'NEWS.DELETE', 'n_article_move_up' => 'NEWS.ADD|NEWS.MODIFY', 'n_article_move_down' => 'NEWS.ADD|NEWS.MODIFY', 'n_article_approve' => 'NEWS.ADD|NEWS.MODIFY', 'n_article_decline' => 'NEWS.ADD|NEWS.MODIFY', 'n_add_article' => 'NEWS.ADD', 'n_edit_article' => 'NEWS.MODIFY', ); checkActionPermission($action_mapping, $Action); // permission checking: end switch($Action) { case "m_cat_delete": if($ro_perm) break; if(isset($CatDeleteList)) { $CatList = $CatDeleteList; if(is_array($CatList)) { for($i=0;$iClearCategoryItems($c,"CategoryItems"); } } else if(is_numeric($CatList)) { $objArticleList->ClearCategoryItems($CatList,"CategoryItems"); } if(!is_array($CatList)) $CatList=Array($CatList); UpdateCategoryCount("Article", $CatList, $objArticleList->GetListTypes()); } break; case "m_paste": /* category paste */ if($ro_perm) break; if($PastedCatIds) { $cache_cat_ids=Array(); foreach($PastedCatIds as $SourceCat => $DestCat) { $cache_cat_ids[$SourceCat]=1; $cache_cat_ids[$DestCat]=1; $objArticleList->Clear(); $objArticleList->LoadArticles("CategoryId=$SourceCat",""); if($objArticleList->NumItems()>0) { foreach($objArticleList->Items as $item) { /* fields from categoryitems table */ $item->UnsetField("CategoryId"); $item->UnsetField("ItemResourceId"); $item->UnsetField("PrimaryCat"); $item->CopyToNewResource($DestCat, 'Title'); $item->AddToCategory($DestCat); } } } UpdateCategoryCount("Article", array_keys($cache_cat_ids), $objArticleList->GetListTypes()); } break; case "n_article_delete": if($ro_perm) break; if (count($_POST["newslist"]) != 0) { $objArticleList->FlushCache($_POST["newslist"]); foreach($_POST["newslist"] as $newsid) $objArticleList->Delete_Item($newsid); } break; case "n_article_move_up": if($ro_perm) break; if (isset($_POST["newslist"])) foreach($_POST["newslist"] as $id) { $a = $objArticleList->GetItem($id); $a->MoveUp(); } break; case "n_article_move_down": if($ro_perm) break; if (isset($_POST["newslist"])) { $newslist=array_reverse($_POST["newslist"]); foreach($newslist as $id) { $a = $objArticleList->GetItem($id); $a->MoveDown(); } } break; case "n_article_approve": if($ro_perm) break; if (isset($_POST["newslist"])) { $cat_ids=Array(); foreach($_POST["newslist"] as $id) { $a = $objArticleList->GetItem($id); if($a->Get("Status")==-2) { $OrgId = $a->Get("OrgId"); if($OrgId) { $org = $objArticleList->GetItem($OrgId); $OldResId = $org->Get("ResourceId"); $NewResId = $a->Get("ResourceId"); //$ExpireInterval = $objConfig->Get("link_ExpireMod_Value") * $objConfig->Get("link_ExpireMod_Interval"); //if($ExpireInterval>0) // $l->Set("Expire",adodb_date("U")+$ExpireInterval); $a->Set("OrgId",0); $a->Approve(); $cat_ids[]=$org->GetPrimaryCategory(); $org->DeleteCustomData(); $org->Delete(TRUE); } } else { $a->Approve(); $cat_ids[]=$a->GetPrimaryCategory(); } } if($cat_ids) UpdateCategoryCount("Article",$cat_ids,$objArticleList->GetListTypes()); } break; case "n_article_decline": if($ro_perm) break; if (isset($_POST["newslist"])) { $cat_ids = Array(); foreach($_POST["newslist"] as $id) { $a = $objArticleList->GetItem($id); $cat_ids[] = $a->GetPrimaryCategory(); if($a->Get("Status")==-2) { $a->Delete(); } else $a->Deny(); } UpdateCategoryCount("Article", $cat_ids, $objArticleList->GetListTypes()); } break; case "n_add_category": $objEditItems = new clsNewsList(); $objEditItems->SourceTable = $objSession->GetEditTable("News"); $r = $_POST["ResourceId"]; $i = $objEditItems->GetItemByField("ResourceId",$_POST["ResourceId"]); $Primary = $i->GetPrimaryCategory($objSession->GetEditTable("CategoryItems")); $objSession->SetVariable("HasChanges", 1); if(is_object($i)) { $table = $objSession->GetEditTable("CategoryItems"); $CatList = explode(",",$_POST["CatList"]); // Get List of currect categories article is in $link_cats = $i->CategoryMemberList($table); $link_cats_arr = explode(",", $link_cats); if (count($CatList)) { for($j=0; $j < count($CatList);$j++) { if($CatList[$j]) { $c = $objCatList->GetByResource($CatList[$j]); $cat = $c->Get("CategoryId"); if(($cat>0) && !in_array($cat, $link_cats_arr)) { $i->AddToCategory($cat,$table); } } } } } break; case "n_cat_delete": $objSession->SetVariable("HasChanges", 1); $objEditItems = new clsNewsList(); $objEditItems->SourceTable = $objSession->GetEditTable("News"); $table = $objSession->GetEditTable("CategoryItems"); $r = $_POST["ResourceId"]; $i = $objEditItems->GetItemByField("ResourceId",$_POST["ResourceId"]); if(is_object($i)) { $CatCount = $i->CategoryMemberCount($table); $Primary = $i->GetPrimaryCategory(); if($CatCount==count($CatList)) { $sql = "DELETE FROM $table WHERE CategoryId=$cat AND ItemResourceId=$r AND PrimaryCat=0"; $ado->Execute($sql); } else { $CatList = $_POST["itemlist"]; $ado = &GetADODBConnection(); for($x=0;$xExecute($sql); $CatCount--; } } } for($x=0;$x0)) { if($cat==$Primary && $CatCount>1) { $sql = "DELETE FROM $table WHERE CategoryId=$cat AND ItemResourceId=$r"; if((int)$_GLOBALS["debuglevel"]) echo $sql; $ado->Execute($sql); $CatCount--; } } } } } break; case 'n_primary_cat': // change primary category of the link $objEditItems = new clsNewsList(); $objEditItems->SourceTable = $objSession->GetEditTable("News"); $article = $objEditItems->GetItemByField('ResourceId', $_REQUEST['ResourceId']); if( is_object($article) ) { $new_cat = array_shift($_REQUEST['itemlist']); $ci_table = $objSession->GetEditTable('CategoryItems'); $article->SetPrimaryCategory($new_cat, $ci_table); } break; case "n_add_article": $application =& kApplication::Instance(); $application->SetVar('n_mode', 't'); if($_POST["NewsEditStatus"]!=2) { $CreatedOn = DateTimestamp($_POST["news_date"],GetDateFormat(0, true)); $EndOn = DateTimestamp($_POST["news_enddate"],GetDateFormat(0, true)); $StartDate = DateTimestamp($_POST["news_startdate"],GetDateFormat(0, true)); $login = trim($_POST["news_author"]); if(strlen($login)) { $u = $objUsers->GetItemByField("Login",$login); if(is_object($u)) { $CreatedById = $u->Get("PortalUserId"); if($CreatedById==0) $CreatedById = $objSession->Get("PortalUserId"); } else $CreatedById = $objSession->Get("PortalUserId"); } else $CreatedById = $objSession->Get("PortalUserId"); $html = (int)$_POST["html_enable"]; $Status = (int)$_POST["status"]; $Hot = (int)$_POST["itemhot"]; $Pop = (int)$_POST["itempop"]; $New = (int)$_POST["itemnew"]; $pick = (int)$_POST["news_pick"]; $leading = (int)$_POST["news_leading"]; $leading_cat = (int)$_POST["news_leading_cat"]; $Priority = (int)$_POST["news_priority"]; $news_excerpt = $_POST["news_excerpt"]; if($_POST["excerpt_generate"] == 1 || strlen($news_excerpt)==0) { $tempbody = strip_tags($_POST["news_body"]); $len = strlen($tempbody); if ($len < 100) $news_excerpt = $tempbody; else { $news_excerpt = substr(strip_tags($tempbody), 0, 100); if(substr($news_excerpt,-1)!=" ") { $pos = strrpos($news_excerpt," "); if($pos) $news_excerpt = substr($news_excerpt,0,$pos); } $news_excerpt .= ".."; } } $objEditItems = new clsNewsList(); $objEditItems->SourceTable = $objSession->GetEditTable("News"); $posted_hits = $_POST['news_hits_show']; $posted_hits_arr = explode('.', $_POST['news_hits']); $save_hits = $_POST['news_hits']; if ($posted_hits_arr[0] != $posted_hits) { $save_hits = $posted_hits; } $l = $objEditItems->Add_News($_POST["CategoryId"], inp_escape($_POST["news_title"], $html), inp_escape($news_excerpt, $html), inp_escape($_POST["news_author"]), inp_escape($_POST["news_body"], $html), $CreatedOn, $EndOn, $StartDate, $Status, $pick, $New,$Pop,$Hot, $_POST["news_rating"],$_POST["news_votes"],$save_hits, $leading, $leading_cat, $Priority,$CreatedById,$html, GetVar('auto_filename'), GetVar('filename') ); saveCustomFields('n', $l->Get('ResourceId'), 2); } break; case "n_edit_article": $application =& kApplication::Instance(); $application->SetVar('n_mode', 't'); if($_POST["NewsEditStatus"]!=2) { $CreatedOn = DateTimestamp($_POST["news_date"],GetDateFormat(0, true)); $EndOn = DateTimestamp($_POST["news_enddate"],GetDateFormat(0, true)); $StartDate = DateTimestamp($_POST["news_startdate"],GetDateFormat(0, true)); $login = trim($_POST["news_author"]); if(strlen($login)) { $u = $objUsers->GetItemByField("Login",$login); if(is_object($u)) { $CreatedById = $u->Get("PortalUserId"); if($CreatedById==0) $CreatedById = $objSession->Get("PortalUserId"); } else $CreatedById = $objSession->Get("PortalUserId"); } else $CreatedById = $objSession->Get("PortalUserId"); $html = (int)$_POST["html_enable"]; $Status = (int)$_POST["status"]; $Hot = (int)$_POST["itemhot"]; $Pop = (int)$_POST["itempop"]; $New = (int)$_POST["itemnew"]; $pick = (int)$_POST["news_pick"]; $leading = (int)$_POST["news_leading"]; $leading_cat = (int)$_POST["news_leading_cat"]; $Priority = (int)$_POST["news_priority"]; if ($_POST["excerpt_generate"] == 1 || strlen($news_excerpt)==0) { $len = strlen($_POST["news_body"]); if ($len < 100) $news_excerpt = $_POST["news_body"]; else $news_excerpt = substr(strip_tags($_POST["news_body"]), 0, 100); } else { $news_excerpt = $_POST["news_excerpt"]; } $objEditItems = new clsNewsList(); $objEditItems->SourceTable = $objSession->GetEditTable("News"); $posted_hits = $_POST['news_hits_show']; $posted_hits_arr = explode('.', $_POST['news_hits']); $save_hits = $_POST['news_hits']; if ($posted_hits_arr[0] != $posted_hits) { $save_hits = $posted_hits; } $l = $objEditItems->Edit_News($_POST["NewsId"], inp_escape($_POST["news_title"],$html), inp_escape($news_excerpt, $html), inp_escape($_POST["news_author"]), inp_escape($_POST["news_body"], $html), $CreatedOn, $EndOn, $StartDate, $Status, $pick, $New, $Pop, $Hot, $_POST["news_rating"], $_POST["news_votes"], $save_hits, $CreatedById,$leading, $leading_cat, $Priority,$html, GetVar('auto_filename'), GetVar('filename') ); saveCustomFields('n', $l->Get("ResourceId"), 2); } break; case "n_article_cut": if($ro_perm) break; if(isset($_POST["newslist"])) { $objArticleList->CopyToClipboard("CUT","NewsId",$_POST["newslist"]); } break; case "n_article_copy": if($ro_perm) break; if(isset($_POST["newslist"])) { $objArticleList->CopyToClipboard("COPY","NewsId",$_POST["newslist"]); } break; // Used from JS case "news_paste": if($ro_perm) break; if($objArticleList->ItemsOnClipboard()>0) { $objArticleList->PasteFromClipboard($objCatList->CurrentCategoryID(),"Title"); UpdateCategoryCount("Article", $objCatList->CurrentCategoryID(), $objArticleList->ListType); } break; } if( ! $objSession->HasSystemPermission("SYSTEM_ACCESS.READONLY") ) { /* Handle the status of news item edit tabs */ if( GetVar('NewsEditStatus') == 1) { $article_ids = $objArticleList->CopyFromEditTable("NewsId"); if ($article_ids) { $objCustomDataList->CopyFromEditTable('n'); } $objArticleList->Clear(); $objImages = new clsImageList(); $objImages->CopyFromEditTable("ImageId"); $objArticleList->FlushCache($article_ids); } /* user hit the cancel button */ if( GetVar('NewsEditStatus') == 2) { $objArticleList->PurgeEditTable("NewsId"); $objArticleList->PurgeCatListEditTable(); $objCustomDataList->PurgeEditTable('n'); $objImages = new clsImageList(); $objImages->PurgeEditTable("ImageId"); $objArticleList->Clear(); } } ?>