Get("CategoryId")."\" _SubCats=\"1\" ";
$txt .=" _ListType=\"category\" _CountCurrent=\"1\" _ItemType=\"$TypeId\" _GroupOnly=\"$GroupOnly\" />";
$tag = new clsHtmlTag($txt);
$ret = $tag->Execute();
}
else
$ret = "";
}
else
{
$ret = (int)$objCountCache->GetCatListTotal($this->Get("CategoryId"));
}
break;
case "totalitems":
/*
@field:cat.totalitems
@description:returns the number of items in the category and all subcategories
*/
$ret = $this->ItemCount();
break;
case "itemdate":
/*
@field:cat.itemdate
@description:Returns the date the cache count was last updated
@attrib:_itemtype:Item name to check
@attrib:_tz:bool:Convert the date to the user's local time
@attrib:_part::Returns part of the date. The following options are available: month,day,year,time_24hr,time_12hr
*/
$typestr = $element->GetAttributeByName('_itemtype');
$type = $objItemTypes->GetTypeByName($typestr);
if(is_object($type))
{
$TypeId = $type->Get("ItemType");
$cc = $objCountCache->GetCountObject(1,$TypeId,$this->get("CategoryId"),0);
if(is_object($cc))
{
$date = $cc->Get("LastUpdate");
}
else
$date = "";
//$date = $this->GetCacheCountDate($TypeId);
if( $element->GetAttributeByName('_tz') )
{
$date = GetLocalTime($date,$objSession->Get("tz"));
}
$part = strtolower($element->GetAttributeByName('_part') );
if(strlen($part))
{
$ret = ExtractDatePart($part,$date);
}
else
{
if($date<=0)
{
$ret = "";
}
else
$ret = LangDate($date);
}
}
else
$ret = "";
break;
case "new":
/*
@field:cat.new
@description:returns text if category's status is "new"
@attrib:_label:lang: Text to return if status is new
*/
if($this->IsNewItem())
{
$ret = $element->GetAttributeByName('_label');
if(!strlen($ret))
$ret = "lu_new";
$ret = language($ret);
}
else
$ret = "";
break;
case "pick":
/*
@field:cat.pick
@description:returns text if article's status is "hot"
@attrib:_label:lang: Text to return if status is "hot"
*/
if($this->Get("EditorsPick")==1)
{
$ret = $element->GetAttributeByName('_label');
if(!strlen($ret))
$ret = "lu_pick";
$ret = language($ret);
}
else
$ret = "";
break;
case "parsetag":
/*
@field:cat.parsetag
@description:returns a tag output with this categoriy set as a current category
@attrib:_tag:: tag name
*/
$tag = new clsHtmlTag();
$tag->name = $element->GetAttributeByName('_tag');
$tag->attributes = $element->attributes;
$tag->attributes["_catid"] = $this->Get("CategoryId");
$ret = $tag->Execute();
break;
/*
@field:cat.relevance
@description:Displays the category relevance in search results
@attrib:_displaymode:: How the relevance should be displayed
- "Numerical": Show the decimal value
- "Bar": Show the HTML representing the relevance. Returns two HTML cells ≶td< with specified background colors
- "Graphical":Show image representing the relevance
@attrib:_onimage::Zero relevance image shown in graphical display mode. Also used as prefix to build other images (i.e. prefix+"_"+percentage+".file_extension"
@attrib:_OffBackGroundColor::Off background color of HTML cell in bar display mode
@attrib:_OnBackGroundColor::On background color of HTML cell in bar display mode
*/
}
if( !isset($ret) ) $ret = parent::ParseObject($element);
}
return $ret;
}
function parsetag($tag)
{
global $objConfig,$objUsers, $m_var_list, $m_var_list_update;
if(is_object($tag))
{
$tagname = $tag->name;
}
else
$tagname = $tag;
switch($tagname)
{
case "cat_id":
return $this->Get("CategoryId");
break;
case "cat_parent":
return $this->Get("ParentId");
break;
case "cat_fullpath":
return $this->Get("CachedNavbar");
break;
case "cat_name":
return inp_unescape($this->Get("Name"));
break;
case "cat_desc":
return inp_unescape($this->Get("Description"));
break;
case "cat_priority":
if($this->Get("Priority")!=0)
{
return (int)$this->Get("Priority");
}
else
return "";
break;
case "cat_pick":
if ($this->Get("EditorsPick"))
return "pick";
break;
case "cat_status":
return $this->Get("Status");
break;
case "cat_Pending":
return $this->Get("Name");
break;
case "cat_pop":
if($this->IsPopItem())
return "pop";
break;
case "cat_new":
if($this->IsNewItem())
return "new";
break;
case "cat_hot":
if($this->IsHotItem())
return "hot";
break;
case "cat_metakeywords":
return inp_unescape($this->Get("MetaKeywords"));
break;
case "cat_metadesc":
return inp_unescape($this->Get("MetaDescription"));
break;
case "cat_createdby":
return $objUsers->GetUserName($this->Get("CreatedById"));
break;
case "cat_resourceid":
return $this->Get("ResourceId");
break;
case "cat_sub_cats":
return $this->GetSubCats($objConfig->Get("SubCat_ListCount"));
break;
case "cat_link":
return $this->Cat_Link();
break;
case "subcat_count":
return $this->SubCatCount();
break;
case "cat_itemcount":
return (int)$this->GetTotalItemCount();
break;
case "cat_link_admin":
$m_var_list_update["cat"] = $this->Get("CategoryId");
$m_var_list_update["p"] = 1;
$ret = $_SERVER["PHP_SELF"]."?env=" . BuildEnv();
unset($m_var_list_update["cat"]);
unset($m_var_list_update["p"]);
return $ret;
break;
case "cat_admin_icon":
$ret = $this->StatusIcon();
return $ret;
break;
case "cat_link_selector":
$m_var_list_update["cat"] = $this->Get("CategoryId");
$ret = $_SERVER["PHP_SELF"]."?env=" . BuildEnv();
unset($m_var_list_update["cat"]);
return $ret;
break;
case "cat_link_edit":
$m_var_list_update["id"] = $this->Get("CategoryId");
$ret = "addcategory.php?env=" . BuildEnv();
unset($m_var_list_update["id"]);
return $ret;
break;
case "cat_date":
return LangDate($this->Get("CreatedOn"));
break;
case "cat_num_cats":
return $this->Get("CachedDescendantCatsQty");
break;
case "cell_back":
if ($m_var_list_update["cat_cell"]=="#cccccc")
{
$m_var_list_update["cat_cell"]="#ffffff";
return "#ffffff";
}
else
{
$m_var_list_update["cat_cell"]="#cccccc";
return "#cccccc";
}
break;
default:
return "Undefined:$tagname";
}
}
function ParentNames()
{
global $objCatList;
if(strlen($this->Get("CachedNavbar"))==0)
{
$nav = "";
//echo "Rebuilding Navbar..
\n";
if(strlen($this->Get("ParentPath"))==0)
{
$this->UpdateCachedPath();
}
$cats = explode("|",substr($this->Get("ParentPath"),1,-1));
foreach($cats as $catid)
{
$cat =& $objCatList->GetCategory($catid);
if(is_object($cat))
{
if(strlen($cat->Get("Name")))
$names[] = $cat->Get("Name");
}
}
$nav = implode(">", $names);
$this->Set("CachedNavbar",$nav);
$this->Update();
}
$res = explode(">",$this->Get("CachedNavbar"));
return $res;
}
function UpdateCacheCounts()
{
global $objItemTypes;
$CatId = $this->Get("CategoryId");
if($CatId>0)
{
//echo "Updating count for ".$this->Get("CachedNavbar")."
\n";
UpdateCategoryCount(0,$CatId);
}
}
}
class clsCatList extends clsItemList //clsItemCollection
{
//var $Page; // no need because clsItemList class used instead of clsItemCollection
//var $PerPageVar;
function clsCatList()
{
global $m_var_list;
$this->clsItemCollection();
$this->classname="clsCategory";
$this->AdminSearchFields = array("Name","Description");
$this->Page = (int)$m_var_list["p"];
$this->PerPageVar = "Perpage_Category";
$this->SourceTable = GetTablePrefix()."Category";
$this->BasePermission="CATEGORY";
$this->DefaultPerPage = 20;
}
function SaveNewPage()
{
global $m_var_list;
$m_var_list["p"] = $this->Page;
}
function GetCountSQL($PermName,$CatId=NULL, $GroupId=NULL, $AdditonalWhere="")
{
global $objSession, $objPermissions, $objCatList;
$ltable = $this->SourceTable;
$acl = $objSession->GetACLClause();
$cattable = GetTablePrefix()."CategoryItems";
$CategoryTable = GetTablePrefix()."Category";
$ptable = GetTablePrefix()."PermCache";
$VIEW = $objPermissions->GetPermId($PermName);
$sql = "SELECT count(*) as CacheVal FROM $ltable ";
$sql .="INNER JOIN $ptable ON ($ltable.CategoryId=$ptable.CategoryId) ";
$sql .="WHERE ($acl AND PermId=$VIEW AND $ltable.Status=1) ";
if(strlen($AdditonalWhere)>0)
{
$sql .= "AND (".$AdditonalWhere.")";
}
return $sql;
}
function CountCategories($attribs)
{
global $objSession;
$cat = $attribs["_catid"];
if(!is_numeric($cat))
{
$cat = $this->CurrentCategoryID();
}
if((int)$cat>0)
$c = $this->GetCategory($cat);
if($attribs["_subcats"] && $cat>0)
{
$ParentWhere = "(ParentPath LIKE '".$c->Get("ParentPath")."%' AND ".$this->SourceTable.".CategoryId != $cat)";
}
if($attribs["_today"])
{
$today = mktime(0,0,0,date("m"),date("d"),date("Y"));
$TodayWhere = "(CreatedOn>=$today)";
}
if($attribs["_grouponly"])
{
$GroupList = $objSession->Get("GroupList");
}
else
$GroupList = NULL;
$where = "";
if(strlen($ParentWhere))
{
$where = $ParentWhere;
}
if(strlen($TodayWhere))
{
if(strlen($where))
$where .=" AND ";
$where .= $TodayWhere;
}
$sql = $this->GetCountSQL("CATEGORY.VIEW",$cat,$GroupList,$where);
// echo "SQL: ".$sql."
";
$rs = $this->adodbConnection->Execute($sql);
if($rs && !$rs->EOF)
{
$ret = $rs->fields["CacheVal"];
}
else
$ret = 0;
return $ret;
}
function CurrentCategoryID()
{
global $m_var_list;
return (int)$m_var_list["cat"];
}
function NumCategories()
{
return $this->NumItems();
}
function &CurrentCat()
{
//return $this->GetCategory($this->CurrentCategoryID());
return $this->GetItem($this->CurrentCategoryID());
}
function &GetCategory($CatID)
{
return $this->GetItem($CatID);
}
function GetByResource($ResId)
{
return $this->GetItemByField("ResourceId",$ResId);
}
function QueryOrderByClause($EditorsPick=FALSE,$Priority=FALSE,$UseTableName=FALSE)
{
global $objSession;
if($UseTableName)
{
$TableName = $this->SourceTable.".";
}
else
$TableName = "";
$Orders = array();
if($EditorsPick)
{
$Orders[] = $TableName."EditorsPick DESC";
}
if($Priority)
{
$Orders[] = $TableName."Priority DESC";
}
$FieldVar = "Category_Sortfield";
$OrderVar = "Category_Sortorder";
if(is_object($objSession))
{
if(strlen($objSession->GetPersistantVariable($FieldVar))>0)
{
$Orders[] = trim($TableName.$objSession->GetPersistantVariable($FieldVar) . " ".
$objSession->GetPersistantVariable($OrderVar));
}
}
$FieldVar = "Category_Sortfield2";
$OrderVar = "Category_Sortorder2";
if(is_object($objSession))
{
if(strlen($objSession->GetPersistantVariable($FieldVar))>0)
{
$Orders[] = trim($TableName.$objSession->GetPersistantVariable($FieldVar) . " ".
$objSession->GetPersistantVariable($OrderVar));
}
}
if(count($Orders)>0)
{
$OrderBy = "ORDER BY ".implode(", ",$Orders);
}
else
$OrderBy="";
return $OrderBy;
}
function LoadCategories($where="", $orderBy = "", $no_limit = true, $fix_method = 'set_first')
{
// load category list using $where clause
// apply ordering specified in $orderBy
// show all cats ($no_limit = true) or only from current page ($no_limit = false)
// in case if stored page is greather then page count issue page_fixing with
// method specified (see "FixInvalidPage" method for details)
$PerPage = $this->GetPerPage();
$this->QueryItemCount = TableCount($this->SourceTable,$where,0);
if($no_limit == false)
{
$this->FixInvalidPage($fix_method);
$Start = ($this->Page-1) * $PerPage;
$limit = "LIMIT ".$Start.",".$PerPage;
}
else
$limit = NULL;
return $this->Query_Category($where, $orderBy, $limit);
}
function Query_Category($whereClause="",$orderByClause="",$limit=NULL)
{
global $m_var_list, $objSession, $Errors, $objPermissions;
$GroupID = $objSession->Get("GroupID");
$resultset = array();
$table = $this->SourceTable;
$ptable = GetTablePrefix()."PermCache";
$CAT_VIEW = $objPermissions->GetPermId("CATEGORY.VIEW");
if(!$objSession->HasSystemPermission("ADMIN"))
{
$sql = "SELECT * FROM $table INNER JOIN $ptable ON ($ptable.CategoryId=$table.CategoryId)";
$acl_where = $objSession->GetACLClause();
if(strlen($whereClause))
{
$sql .= " WHERE ($acl_where) AND PermId=$CAT_VIEW AND ".$whereClause;
}
else
$sql .= " WHERE ($acl_where) AND PermId=$CAT_VIEW ";
}
else
{
$sql ="SELECT * FROM $table ".($whereClause ? "WHERE $whereClause" : '');
}
$sql .=" ".$orderByClause;
if(isset($limit) && strlen(trim($limit)))
$sql .= " ".$limit;
if($objSession->HasSystemPermission("DEBUG.LIST"))
echo $sql;
return $this->Query_item($sql);
}
function CountPending()
{
return TableCount($this->SourceTable,"Status=".STATUS_PENDING,0);
}
function GetPageLinkList($dest_template=NULL,$page="",$PagesToList=10,$HideEmpty=TRUE)
{
global $objConfig, $m_var_list_update, $var_list_update, $var_list;
if(!strlen($page))
$page = GetIndexURL();
$PerPage = $this->GetPerPage();
$NumPages = ceil( $this->GetNumPages($PerPage) );
if($NumPages == 1 && $HideEmpty) return '';
if(strlen($dest_template))
{
$var_list_update["t"] = $dest_template;
}
else
$var_list_update["t"] = $var_list["t"];
$o = "";
if($this->Page>$NumPages)
$this->Page=$NumPages;
$StartPage = (int)$this->Page - ($PagesToList/2);
if($StartPage<1)
$StartPage=1;
$EndPage = $StartPage+($PagesToList-1);
if($EndPage>$NumPages)
{
$EndPage = $NumPages;
$StartPage = $EndPage-($PagesToList-1);
if($StartPage<1)
$StartPage=1;
}
$o = "";
if($StartPage>1)
{
$m_var_list_update["p"] = $this->Page-$PagesToList;
$prev_url = $page."?env=".BuildEnv();
$o .= "<<";
}
for($p=$StartPage;$p<=$EndPage;$p++)
{
if($p!=$this->Page)
{
$m_var_list_update["p"]=$p;
$href = $page."?env=".BuildEnv();
$o .= " $p ";
}
else
{
$o .= "$p";
}
}
if($EndPage<$NumPages && $EndPage>0)
{
$m_var_list_update["p"]=$this->Page+$PagesToList;
$next_url = $page."?env=".BuildEnv();
$o .= " >>";
}
unset($m_var_list_update,$var_list_update["t"] );
return $o;
}
function GetAdminPageLinkList($url)
{
global $objConfig, $m_var_list_update, $var_list_update, $var_list;
$PerPage = $this->GetPerPage();
$NumPages = ceil($this->GetNumPages($PerPage));
$o = "";
if($this->Page>1)
{
$m_var_list_update["p"]=$this->Page-1;
$prev_url = $url."?env=".BuildEnv();
unset($m_var_list_update["p"]);
$o .= "<<";
}
if($this->Page<$NumPages)
{
$m_var_list_update["p"]=$this->Page+1;
$next_url = $url."?env=".BuildEnv();
unset($m_var_list_update["p"]);
}
for($p=1;$p<=$NumPages;$p++)
{
if($p != $this->Page)
{
$m_var_list_update["p"]=$p;
$href = $url."?env=".BuildEnv();
unset($m_var_list_update["p"]);
$o .= " $p ";
}
else
$o .= "$p";
}
if($this->Page < $NumPages)
$o .= ">>";
return $o;
}
function Search_Category($orderByClause)
{
global $objSession, $objConfig, $Errors;
$PerPage = $this->GetPerPage();
$Start = ($this->Page-1) * $PerPage;
$objResults = new clsSearchResults("Category","clsCategory");
$this->Clear();
$this->Categories = $objResults->LoadSearchResults($Start,$PerPage);
return $this->Categories;
}
function GetSubCats($ParentCat)
{
return $this->Query_Category("ParentId=".$ParentCat,"");
}
function AllSubCats($ParentCat)
{
$c =& $this->GetCategory($ParentCat);
$sql = "SELECT * FROM ".$this->SourceTable." WHERE ParentPath LIKE '".$c->Get("ParentPath")."%'";
$rs = $this->adodbConnection->Execute($sql);
$subcats = array();
while($rs && !$rs->EOF)
{
if($rs->fields["CategoryId"]!=$ParentCat)
{
$subcats[] = $rs->fields["CategoryId"];
}
$rs->MoveNext();
}
if($ParentCat>0)
{
if($c->Get("CachedDescendantCatsQty")!=count($subcats))
{
$c->Set("CachedDescendantCatsQty",count($subcats));
}
}
return $subcats;
}
function cat_navbar($admin=0, $cat, $target_template, $separator = " > ", $LinkLeaf = FALSE,
$root = 0,$RootTemplate="",$modcat=0, $ModTemplate="", $LinkRoot = FALSE)
{
// draw category navigation bar (at top)
global $Errors, $var_list_update, $var_list, $m_var_list_update, $m_var_list, $objConfig;
$selector = isset($_REQUEST['Selector']) ? '&Selector='.$_REQUEST['Selector'] : '';
$new = isset($_REQUEST['new']) ? '&new='.$_REQUEST['new'] : '';
$nav = "";
$m_var_list_update["p"]=1;
if(strlen($target_template)==0)
$target_template = $var_list["t"];
if($cat == 0)
{
$cat_name = language($objConfig->Get("Root_Name"));
if ($LinkRoot)
{
$var_list_update["t"] = strlen($RootTemplate)? $RootTemplate : $target_template;
$nav = "$cat_name"; }
else
$nav = "$cat_name";
}
else
{
$nav = array();
$c =& $this->GetCategory($cat);
$nav_unparsed = $c->Get("ParentPath");
if(strlen($nav_unparsed)==0)
{
$c->UpdateCachedPath();
$nav_unparsed = $c->Get("ParentPath");
}
//echo " Before $nav_unparsed ";
if($root)
{
$r =& $this->GetCategory($root);
$rpath = $r->Get("ParentPath");
$nav_unparsed = substr($nav_unparsed,strlen($rpath),-1);
$cat_name = $r->Get("Name");
$m_var_list_update["cat"] = $root;
if($cat == $catid && !$LinkLeaf)
{
$nav[] = "".$cat_name.""; //href=\"browse.php?env=". BuildEnv() ."\"
}
else
{
if ($admin == 1)
{
$nav[] = "".$cat_name."";
}
else
{
if(strlen($RootTemplate))
{
$var_list_update["t"] = $RootTemplate;
}
else
{
$var_list_update["t"] = $target_template;
}
$nav[] = "".$cat_name."";
}
}
}
else
{
$nav_unparsed = substr($nav_unparsed,1,-1);
$cat_name = language($objConfig->Get("Root_Name"));
$m_var_list_update["cat"] = 0;
if($cat == 0)
{
$nav[] = "".$cat_name.""; //href=\"browse.php?env=". BuildEnv() ."\"
}
else
{
if ($admin == 1)
{
$nav[] = "".$cat_name."";
}
else
{
if(strlen($RootTemplate))
{
$var_list_update["t"] = $RootTemplate;
}
else
$var_list_update["t"] = $target_template;
$nav[] = "".$cat_name."";
}
}
}
//echo " After $nav_unparsed
\n";
if(strlen($target_template)==0)
$target_template = $var_list["t"];
$cats = explode("|", $nav_unparsed);
foreach($cats as $catid)
{
if($catid)
{
$c =& $this->GetCategory($catid);
if(is_object($c))
{
$cat_name = $c->Get("Name");
$m_var_list_update["cat"] = $catid;
if($catid==$modcat && strlen($ModTemplate)>0)
{
$t = $ModTemplate;
}
else
$t = $target_template;
if($cat == $catid && !$LinkLeaf)
{
$nav[] = "".$cat_name."";
}
else
{
if ($admin == 1)
{
$nav[] = "".$cat_name."";
}
else
{
$var_list_update["t"] = $t;
$nav[] = "".$cat_name."";
unset($var_list_update["t"]);
}
}
unset($m_var_list_update["cat"]);
}
}
}
$nav = implode($separator, $nav);
}
return $nav;
}
function &Add($ParentId, $Name, $Description, $CreatedOn, $EditorsPick, $Status, $Hot, $New, $Pop,
$Priority, $MetaKeywords,$MetaDesc)
{
global $objSession;
$UserId = $objSession->Get("UserId");
$d = new clsCategory(NULL);
$d->tablename = $this->SourceTable;
if($d->UsingTempTable())
$d->Set("CategoryId",-1);
$d->idfield = "CategoryId";
$d->Set(array("ParentId", "Name", "Description", "CreatedOn", "EditorsPick", "Status", "HotItem",
"NewItem","PopItem", "Priority", "MetaKeywords", "MetaDescription", "CreatedById"),
array($ParentId, $Name, $Description, $CreatedOn, $EditorsPick, $Status, $Hot, $New,
$Pop, $Priority, $MetaKeywords,$MetaDesc, $UserId));
$d->Create();
if($Status==1)
{
$d->SendUserEventMail("CATEGORY.ADD",$objSession->Get("PortalUserId"));
$d->SendAdminEventMail("CATEGORY.ADD");
}
else
{
$d->SendUserEventMail("CATEGORY.ADD.PENDING",$objSession->Get("PortalUserId"));
$d->SendAdminEventMail("CATEGORY.ADD.PENDING");
}
$d->UpdateCachedPath();
//RunUp($ParentId, "Increment_Count");
return $d;
}
function &Edit_Category($CategoryId, $Name, $Description, $CreatedOn, $EditorsPick, $Status, $Hot,
$NewItem, $Pop, $Priority, $MetaKeywords,$MetaDesc)
{
$d =& $this->GetCategory($CategoryId);
$d->Set(array("Name", "Description", "CreatedOn", "EditorsPick", "Status", "HotItem",
"NewItem", "PopItem", "Priority", "MetaKeywords","MetaDescription"),
array($Name, $Description, $CreatedOn, $EditorsPick, $Status, $Hot, $NewItem,
$Pop, $Priority, $MetaKeywords,$MetaDesc));
$d->Update();
$d->UpdateCachedPath();
return $d;
}
function Move_Category($Id, $ParentTo)
{
global $objCatList;
$d =& $this->GetCategory($Id);
$oldparent = $d->Get("ParentId");
$ChildList = $d->GetSubCatIds();
/*
echo "Target Parent Id: $ParentTo
\n";
echo "";print_r($ChildList); echo "
";
echo "Old Parent: $oldparent
\n";
echo "ID: $Id
\n";
*/
/* sanity checks */
if(!in_array($ParentTo,$ChildList) && $oldparent != $ParentTo && $oldparent != $Id &&
$Id != $ParentTo)
{
$d->Set("ParentId", $ParentTo);
$d->Update();
$d->UpdateCachedPath();
RunUp($oldparent, "Decrement_Count");
RunUp($ParentTo, "Increment_Count");
RunDown($ParentTo, "UpdateCachedPath");
return TRUE;
}
else
{
global $Errors;
$Errors->AddAdminUserError("la_error_move_subcategory");
return FALSE;
}
die();
}
function Copy_CategoryTree($Id, $ParentTo)
{
global $PastedCatIds;
$new = $this->Copy_Category($Id, $ParentTo);
if($new)
{
$PastedCatIds[$Id] = $new;
$sql = "SELECT CategoryId from ".GetTablePrefix()."Category where ParentId=$Id";
$result = $this->adodbConnection->Execute($sql);
if ($result && !$result->EOF)
{
while(!$result->EOF)
{
$this->Copy_CategoryTree($result->fields["CategoryId"], $new);
$result->MoveNext();
}
}
}
return $new;
}
function Copy_Category($Id, $ParentTo)
{
global $objGroups;
$src = $this->GetCategory($Id);
$Children = $src->GetSubCatIds();
if($Id==$ParentTo || in_array($ParentTo,$Children))
{
/* sanity error here */
global $Errors;
$Errors->AddAdminUserError("la_error_copy_subcategory");
return 0;
}
$dest = $src;
$dest->Set("ParentId", $ParentTo);
if ($src->get("ParentId") == $ParentTo)
{
$OldName = $src->Get("Name");
if(substr($OldName,0,5)=="Copy ")
{
$parts = explode(" ",$OldName,4);
if($parts[2]=="of" && is_numeric($parts[1]))
{
$Name = $parts[3];
}
else
if($parts[1]=="of")
{
$Name = $parts[2]." ".$parts[3];
}
else
$Name = $OldName;
}
else
$Name = $OldName;
//echo "New Name: $Name
";
$dest->Set("Name", $Name);
$Names = CategoryNameCount($ParentTo,$Name);
//echo "Names Count: ".count($Names)."
";
if(count($Names)>0)
{
$NameCount = count($Names);
$found = FALSE;
$NewName = "Copy of $Name";
if(!in_array($NewName,$Names))
{
//echo "Matched on $NewName in:
\n";
$found = TRUE;
}
else
{
for($x=2;$x<$NameCount+2;$x++)
{
$NewName = "Copy ".$x." of ".$Name;
if(!in_array($NewName,$Names))
{
$found = TRUE;
break;
}
}
}
if(!$found)
{
$NameCount++;
$NewName = "Copy $NameCount of $Name";
}
//echo "New Name: $NewName
";
$dest->Set("Name",$NewName);
}
}
$dest->UnsetIdField();
$dest->Set("CachedDescendantCatsQty",0);
$dest->Set("ResourceId",NULL);
$dest->Create();
$dest->UpdateCachedPath();
$p = new clsPermList();
$p->Copy_Permissions($src->Get("CategoryId"),$dest->Get("CategoryId"));
$glist = $objGroups->GetAllGroupList();
$view = $p->GetGroupPermList($dest, "CATEGORY.VIEW", $glist);
$dest->SetViewPerms("CATEGORY.VIEW",$view,$glist);
RunUp($ParentTo, "Increment_Count");
return $dest->Get("CategoryId");
}
function Delete_Category($Id)
{
global $objSession;
$d =& $this->GetCategory($Id);
if(is_object($d))
{
if($d->Get("CategoryId")==$Id)
{
$d->SendUserEventMail("CATEGORY.DELETE",$objSession->Get("PortalUserId"));
$d->SendAdminEventMail("CATEGORY.DELETE");
$p =& $this->GetCategory($d->Get("ParentId"));
RunDown($d->Get("CategoryId"), "Delete");
RunUp($p->Get("CategoryId"), "Decrement_Count");
RunUp($d->Get("CategoryId"),"ClearCacheData");
}
}
}
function PasteFromClipboard($TargetCat)
{
global $objSession;
$clip = $objSession->GetVariable("ClipBoard");
if(strlen($clip))
{
$ClipBoard = ParseClipboard($clip);
$IsCopy = (substr($ClipBoard["command"],0,4)=="COPY") || ($ClipBoard["source"] == $TargetCat);
$item_ids = explode(",",$ClipBoard["ids"]);
for($i=0;$iGetItem($item_ids[$i]);
if(!$IsCopy)
{
$this->Move_Category($ItemId, $TargetCat);
$clip = str_replace("CUT","COPY",$clip);
$objSession->SetVariable("ClipBoard",$clip);
}
else
{
$this->Copy_CategoryTree($ItemId,$TargetCat);
}
}
}
}
function NumChildren($ParentID)
{
$cat_filter = "m_cat_filter";
global $$cat_filter;
$filter = $$cat_filter;
$adodbConnection = GetADODBConnection();
$sql = "SELECT COUNT(Name) as children from ".$this->SourceTable." where ParentId=" . $ParentID . $filter;
$result = $adodbConnection->Execute($sql);
return $result->fields["children"];
}
function UpdateMissingCacheData()
{
$rs = $this->adodbConnection->Execute("SELECT * FROM ".$this->SourceTable." WHERE ParentPath IS NULL or ParentPath=''");
while($rs && !$rs->EOF)
{
$c = new clsCategory(NULL);
$data = $rs->fields;
$c->SetFromArray($data);
$c->UpdateCachedPath();
$rs->MoveNext();
}
$rs = $this->adodbConnection->Execute("SELECT * FROM ".$this->SourceTable." WHERE CachedNavbar IS NULL or CachedNavBar=''");
while($rs && !$rs->EOF)
{
$c = new clsCategory(NULL);
$data = $rs->fields;
$c->SetFromArray($data);
$c->UpdateCachedPath();
$rs->MoveNext();
}
}
function CopyFromEditTable($idfield)
{
global $objGroups, $objSession, $objPermList;
$objPermList = new clsPermList();
$edit_table = $objSession->GetEditTable($this->SourceTable);
$sql = "SELECT * FROM $edit_table";
$rs = $this->adodbConnection->Execute($sql);
while($rs && !$rs->EOF)
{
$data = $rs->fields;
$c = new $this->classname;
$c->SetFromArray($data);
$c->Dirty();
if($c->Get("CategoryId")>0)
{
$c->Update();
}
else
{
$c->UnsetIdField();
$c->Create();
$sql = "UPDATE ".GetTablePrefix()."Permissions SET CatId=".$c->Get("CategoryId")." WHERE CatId=-1";
$this->adodbConnection->Execute($sql);
}
$c->UpdateCachedPath();
$c->UpdateACL();
$c->SendUserEventMail("CATEGORY.MODIFY",$objSession->Get("PortalUserId"));
$c->SendAdminEventMail("CATEGORY.MODIFY");
$c->Related = new clsRelationshipList();
if(is_object($c->Related))
{
$r = $c->Related;
$r->CopyFromEditTable($c->Get("ResourceId"));
}
//RunDown($c->Get("CategoryId"),"UpdateCachedPath");
//RunDown($c->Get("CategoryId"),"UpdateACL");
unset($c);
unset($r);
$rs->MoveNext();
}
@$this->adodbConnection->Execute("DROP TABLE IF EXISTS $edit_table");
//$this->UpdateMissingCacheData();
}
function PurgeEditTable($idfield)
{
parent::PurgeEditTable($idfield);
$sql = "DELETE FROM ".GetTablePrefix()."Permissions WHERE CatId=-1";
$this->adodbConnection->Execute($sql);
}
function GetExclusiveType($CatId)
{
global $objItemTypes, $objConfig;
$itemtype = NULL;
$c =& $this->GetItem($CatId);
$path = $c->Get("ParentPath");
foreach($objItemTypes->Items as $Type)
{
$RootVar = $Type->Get("ItemName")."_Root";
$RootId = $objConfig->Get($RootVar);
if((int)$RootId)
{
$rcat = $this->GetItem($RootId);
$rpath = $rcat->Get("ParentPath");
$p = substr($path,0,strlen($rpath));
//echo $rpath." vs. .$p [$path]
\n";
if($rpath==$p)
{
$itemtype = $Type;
break;
}
}
}
return $itemtype;
}
}
function RunUp($Id, $function, $Param=NULL)
{
global $objCatList;
$d = $objCatList->GetCategory($Id);
$ParentId = $d->Get("ParentId");
if ($ParentId == 0)
{
if($Param == NULL)
{
$d->$function();
}
else
{
$d->$function($Param);
}
}
else
{
RunUp($ParentId, $function, $Param);
if($Param == NULL)
{
$d->$function();
}
else
{
$d->$function($Param);
}
}
}
function RunDown($Id, $function, $Param=NULL)
{
global $objCatList;
$adodbConnection = GetADODBConnection();
$sql = "select CategoryId from ".GetTablePrefix()."Category where ParentId='$Id'";
$rs = $adodbConnection->Execute($sql);
while($rs && !$rs->EOF)
{
RunDown($rs->fields["CategoryId"], $function, $Param);
$rs->MoveNext();
}
$d = $objCatList->GetCategory($Id);
if($Param == NULL)
{
$d->$function();
}
else
$d->$function($Param);
}
?>