HasSystemPermission("SYSTEM_ACCESS.READONLY"); require_login( !admin_login() && $Action, 'expired=1', true ); // permission checking: begin $action_mapping = Array( 'l_link_delete' => 'LINK.OWNER.DELETE|LINK.DELETE', 'l_link_add' => 'LINK.ADD', 'l_edit_link' => 'LINK.OWNER.MODIFY|LINK.MODIFY', 'l_link_move_up' => 'LINK.ADD|LINK.OWNER.MODIFY|LINK.MODIFY', 'l_link_move_down' => 'LINK.ADD|LINK.OWNER.MODIFY|LINK.MODIFY', 'l_link_approve' => 'LINK.ADD|LINK.OWNER.MODIFY|LINK.MODIFY', 'l_link_decline' => 'LINK.ADD|LINK.OWNER.MODIFY|LINK.MODIFY', ); checkActionPermission($action_mapping, $Action); // permission checking: end switch($Action) { case "m_cat_delete": if($ro_perm) break; if ($CatDeleteList) { if (constOn('K4_LINKS')) { $event = new kEvent('ci:OnDeleteFromCategory'); $event->setEventParam('item_prefix', 'l'); $event->setEventParam('category_ids', $CatDeleteList); $application->HandleEvent($event); break; } $objLinkLink->BasePermission=""; $CatList = $CatDeleteList; if(is_array($CatList)) { for($i=0;$iClearCategoryItems($c,"CategoryItems"); } } else { if(is_numeric($CatList)) { $objLinkList->ClearCategoryItems($CatList,"CategoryItems"); } } $objLinkLink->BasePermission="LINK"; if(!is_array($CatList)) $CatList=Array($CatList); UpdateCategoryCount("Link",$CatList, $objLinkList->GetListTypes() ); } break; case "m_paste": /* category paste */ if($ro_perm) break; if ($PastedCatIds) { if (constOn('K4_LINKS')) { $event = new kEvent('l:OnCatPaste'); $event->setEventParam('cat_ids', $PastedCatIds); $application->HandleEvent($event); break; } $objLinkLink->BasePermission=""; $cache_cat_ids=Array(); foreach ($PastedCatIds as $SourceCat => $DestCat) {// for each pasted category paste links in it $cache_cat_ids[$SourceCat]=1; $cache_cat_ids[$DestCat]=1; $objLinkList->Clear(); $objLinkList->Query_Link(GetTablePrefix()."CategoryItems.CategoryId=$SourceCat"); // get cat links if($objLinkList->NumItems()>0) { foreach($objLinkList->Items as $item) { /* fields from categoryitems table */ $item->UnsetField("CategoryId"); $item->UnsetField("ItemResourceId"); $item->UnsetField("PrimaryCat"); $item->UnsetField("CachedNavBar"); $item->CopyToNewResource($DestCat); $item->AddToCategory($DestCat); } } } $objLinkLink->BasePermission="LINK"; UpdateCategoryCount("Link", array_keys($cache_cat_ids), $objLinkList->GetListTypes()); } break; // Used from JS case "link_paste": if ($ro_perm) break; if (constOn('K4_LINKS')) { $event = new kEvent('l:OnPaste'); $application->HandleEvent($event); } elseif($objLinkList->ItemsOnClipboard()>0) { $objLinkList->PasteFromClipboard($objCatList->CurrentCategoryID(),"Name"); UpdateCategoryCount('Link', 0); } break; case "l_add_category": $objEditItems = new clsLinkList(); $objEditItems->SourceTable = $objSession->GetEditTable("Link"); $r = $_POST["ResourceId"]; $l = $objEditItems->GetItemByField("ResourceId",$_POST["ResourceId"]); if(is_object($l)) { $table = $objSession->GetEditTable("CategoryItems"); $CatList = explode(",",$_POST["CatList"]); // Get List of currect categories link is in $link_cats = $l->CategoryMemberList($table); $link_cats_arr = explode(",", $link_cats); $objSession->SetVariable("HasChanges", 1); if (count($CatList)) { for($i=0;$iGetByResource($CatList[$i]); $cat = $c->Get("CategoryId"); if(($cat>0) && !in_array($cat, $link_cats_arr)) { $l->AddToCategory($cat,$table); } } } } } break; case "l_cat_delete": $objSession->SetVariable("HasChanges", 1); $objEditItems = new clsLinkList(); $objEditItems->SourceTable = $objSession->GetEditTable("Link"); $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"; // echo $sql; } else { $CatList = $_POST["itemlist"]; $ado = &GetADODBConnection(); for($x=0;$xExecute($sql); $CatCount--; } } } for($x=0;$x1) { $sql = "DELETE FROM $table WHERE CategoryId=$cat AND ItemResourceId=$r"; $ado->Execute($sql); $CatCount--; } } } } } break; case 'l_primary_cat': // change primary category of the link $objEditItems = new clsLinkList(); $objEditItems->SourceTable = $objSession->GetEditTable("Link"); $link = $objEditItems->GetItemByField('ResourceId', $_REQUEST['ResourceId']); if( is_object($link) ) { $new_cat = array_shift($_REQUEST['itemlist']); $ci_table = $objSession->GetEditTable('CategoryItems'); $link->SetPrimaryCategory($new_cat, $ci_table); } break; case "l_link_delete": if($ro_perm) break; if (count($_POST["linklist"]) >0) { $objLinkList->FlushCache($_POST["linklist"]); foreach($_POST["linklist"] as $linkid) { $objLinkList->Delete_Item($linkid); } } break; case 'l_link_add': $application =& kApplication::Instance(); $application->SetVar('l_mode', 't'); if ($_POST["LinkEditStatus"] != 2) { $CreatedOn = DateTimestamp($_POST['link_date'],GetDateFormat(0, true)); $CreatedOn += adodb_date('H')*3600 + adodb_date('i')*60 + adodb_date('s'); if (strlen($_POST["link_expire"]) && ((int)$_POST["link_expire"]>0)) { $Expire = DateTimestamp($_POST["link_expire"],GetDateFormat(0, true)); } else { $Expire = 0; } $link_pick = (int)$_POST["link_pick"]; $Status = (int)$_POST["status"]; $Hot=(int)$_POST["itemhot"]; $Pop = (int)$_POST["itempop"]; $New = (int)$_POST["itemnew"]; $html = (int)$_POST["html_enable"]; $Name = inp_escape($_POST["link_name"],$html); $Desc = inp_escape($_POST["link_desc"],$html); $Priority = (int)$_POST["link_priority"]; //echo "Category:".$objCatList->CurrentCategoryID()."
"; $objEditItems = new clsLinkList(); $objEditItems->SourceTable = $objSession->GetEditTable("Link"); if (strlen($_POST["link_owner"])) { if ($_POST["link_owner"] == "root") { $CreatedById = -1; } else { $u = $objUsers->GetItemByField("Login",$_POST["link_owner"]); if (is_object($u)) { $CreatedById = $u->Get("PortalUserId"); } else { $CreatedById = $objSession->Get("PortalUserId"); } } } else { $CreatedById = $objSession->Get("PortalUserId"); } $posted_hits = $_POST['link_hits_show']; $posted_hits_arr = explode('.', $_POST['link_hits']); $save_hits = $_POST['link_hits']; if ($posted_hits_arr[0] != $posted_hits) { $save_hits = $posted_hits; } $l = $objEditItems->Add_Link($objCatList->CurrentCategoryID(), $Name, $Desc, $_POST["link_url"], $CreatedOn, $Expire, $Status, $link_pick, $New, $Pop, $Hot, $CreatedById, (int)$_POST["link_rating"], (int)$_POST["link_votes"],$save_hits, $Priority, GetVar('auto_filename'), GetVar('filename') ); saveCustomFields('l', $l->Get('ResourceId'), 4); } break; case 'l_edit_link': $application =& kApplication::Instance(); $application->SetVar('l_mode', 't'); if ($_POST["LinkEditStatus"] != 2) { $CreatedOn = DateTimestamp($_POST["link_date"],GetDateFormat(0, true)); if (strlen($_POST["link_expire"]) && ((int)$_POST["link_expire"]>0)) { $Expire = DateTimestamp($_POST["link_expire"],GetDateFormat(0, true)); } else { $Expire = 0; } $Status = (int)$_POST["status"]; $Hot=(int)$_POST["itemhot"]; $Pop = (int)$_POST["itempop"]; $New = (int)$_POST["itemnew"]; $link_pick = (int)$_POST["link_pick"]; $html = (int)$_POST["html_enable"]; $Name = inp_escape($_POST["link_name"],$html); $Desc = inp_escape($_POST["link_desc"],$html); $Priority = (int)$_POST["link_priority"]; if (strlen($_POST["link_owner"])) { if ($_POST["link_owner"] == "root") { $CreatedById = -1; } else { $u = $objUsers->GetItemByField("Login",$_POST["link_owner"]); if (is_object($u)) { $CreatedById = $u->Get("PortalUserId"); } else { $CreatedById = $objSession->Get("PortalUserId"); } } } else { $CreatedById = $objSession->Get("PortalUserId"); } $posted_hits = $_POST['link_hits_show']; $posted_hits_arr = explode('.', $_POST['link_hits']); $save_hits = $_POST['link_hits']; if ($posted_hits_arr[0] != $posted_hits) { $save_hits = $posted_hits; } $objEditItems = new clsLinkList(); $objEditItems->SourceTable = $objSession->GetEditTable("Link"); $l = $objEditItems->Edit_Link($_POST["LinkId"], inp_escape($Name, $html), inp_escape($Desc, $html), inp_escape($_POST["link_url"], $html), $CreatedOn, $Expire, $Status, $link_pick, $New, $Pop, $Hot, $_POST["link_rating"],(int)$_POST["link_votes"], $save_hits,$Priority, GetVar('auto_filename'), GetVar('filename') ); $l->Set("CreatedById",$CreatedById); $l->Update(); saveCustomFields('l', $l->Get('ResourceId'), 4); } break; case "l_link_cut": if($ro_perm) break; if(isset($_POST["linklist"])) { $objLinkList->CopyToClipboard("CUT","ResourceId",$_POST["linklist"]); // UpdateCategoryCount("Link"); } break; case "l_link_copy": if($ro_perm) break; if(isset($_POST["linklist"])) { $objLinkList->CopyToClipboard("COPY","ResourceId",$_POST["linklist"]); } break; case "l_link_move_up": if($ro_perm) break; if(isset($_POST["linklist"])) foreach($_POST["linklist"] as $linkid) { $link = $objLinkList->GetItem($linkid); $link->MoveUp(); } break; case "l_link_move_down": if($ro_perm) break; if (isset($_POST["linklist"])) { $linklist=array_reverse($_POST["linklist"]); foreach($linklist as $linkid) { $link = $objLinkList->GetItem($linkid); $link->MoveDown(); } } break; case "l_link_approve": if($ro_perm) break; if (isset($_POST["linklist"])) { $cat_ids=Array(); $db =& GetADODBConnection(); $update_sql = 'UPDATE '.GetTablePrefix().'Listings SET ItemResourceId = %s WHERE ItemResourceId = %s'; foreach($_POST["linklist"] as $id) { $l = $objLinkList->GetItem($id); if($l->Get("Status")==-2) { $OrgId = $l->Get("OrgId"); if($OrgId) { $org = $objLinkList->GetItem($OrgId); $OldResId = $org->Get("ResourceId"); $NewResId = $l->Get("ResourceId"); if ($OldResId) { $db->Execute( sprintf($update_sql, $NewResId, $OldResId) ); } elseif(IsDebugMode()) { echo 'Invalid ResourceID of Original Link: '; print_pre($org->Data); } $ExpireInterval = $objConfig->Get("link_ExpireMod_Value") * $objConfig->Get("link_ExpireMod_Interval"); if($ExpireInterval>0) $l->Set("Expire",adodb_date("U")+$ExpireInterval); $l->Set("OrgId",0); $l->Approve(); $cat_ids[]=$org->GetPrimaryCategory(); $org->DeleteCustomData(); $org->Delete(TRUE); } /*else { $ExpireInterval = $objConfig->Get("link_Expire_Value") * $objConfig->Get("link_Expire_Interval"); if($ExpireInterval>0) $link->Set("Expire",adodb_date("U")+$ExpireInterval); }*/ } else { $l->Approve(); $cat_ids[]=$l->GetPrimaryCategory(); } } if($cat_ids) UpdateCategoryCount("Link",$cat_ids,$objLinkList->GetListTypes() ); } break; case "l_link_decline": if($ro_perm) break; if (isset($_POST["linklist"])) { $cat_ids = Array(); foreach($_POST["linklist"] as $id) { $l = $objLinkList->GetItem($id); $cat_ids[] = $l->GetPrimaryCategory(); if($l->Get("Status")==-2) { $l->Delete(); } else { $l->Deny(); } } UpdateCategoryCount("Link", $cat_ids, $objLinkList->GetListTypes()); } break; case "l_deny_val_link": // deny if($ro_perm) break; if (isset($_POST["itemlist"])) { $cat_ids = Array(); foreach($_POST["itemlist"] as $id) { $l = $objLinkList->GetItem($id); $cat_ids[] = $l->GetPrimaryCategory(); $l->Deny(); } UpdateCategoryCount("Link", $cat_ids, $objLinkList->GetListTypes()); } break; case "l_approve_val_link": // approve if($ro_perm) break; if (isset($_POST["itemlist"])) { $cat_ids = Array(); foreach($_POST["itemlist"] as $id) { $l = $objLinkList->GetItem($id); $cat_ids[] = $l->GetPrimaryCategory(); $l->Approve(); } UpdateCategoryCount("Link", $cat_ids, $objLinkList->GetListTypes()); } break; case "l_delete_val_link": // delete if($ro_perm) break; if (count($_POST["itemlist"]) >0) { $cat_ids = Array(); foreach($_POST["itemlist"] as $id) { $l = $objLinkList->GetItem($id); $cat_ids[] = $l->GetPrimaryCategory(); $objLinkList->Delete_Item($id, true); } } UpdateCategoryCount("Link", $cat_ids, $objLinkList->GetListTypes()); break; case "l_reset_val_status_sel": // reset validation status if($ro_perm) break; if (count($_POST["itemlist"]) >0) { foreach($_POST["itemlist"] as $id) $linksToReset.= $id.", "; $linksToReset = ereg_replace(", $", "", $linksToReset); if (strlen($linksToReset)) { $sql = "DELETE FROM ".GetTablePrefix()."LinkValidation WHERE LinkId IN ($linksToReset)"; $conn1 = &GetADODBConnection(); $conn1->Execute($sql); } } break; } if( ! $objSession->HasSystemPermission("SYSTEM_ACCESS.READONLY") ) { if( GetVar('LinkEditStatus') == 1 ) { $link_ids = $objLinkList->CopyFromEditTable("LinkId"); if ($link_ids) { $objCustomDataList->CopyFromEditTable('l'); } $objImages = new clsImageList(); $objImages->CopyFromEditTable("ImageId"); $objLinkList->Clear(); $objLinkList->FlushCache($link_ids); } if( GetVar('LinkEditStatus') == 2 ) { $objLinkList->PurgeEditTable("LinkId"); $objLinkList->PurgeCatListEditTable(); $objReviewList = new clsItemReviewList(); $objReviewList->PurgeEditTable(); $objImages = new clsImageList(); $objImages->PurgeEditTable("ImageId"); $objCustomDataList->PurgeEditTable('l'); $objLinkList->Clear(); } } ?>