Index: trunk/kernel/include/itemreview.php =================================================================== diff -u -r534 -r642 --- trunk/kernel/include/itemreview.php (.../itemreview.php) (revision 534) +++ trunk/kernel/include/itemreview.php (.../itemreview.php) (revision 642) @@ -1,618 +1,618 @@ -Execute($sql); - if($rs) - { - $count = $rs->fields["DupCount"]; - } - return ($count>0); -} - -RegisterPrefix("clsItemReview","review","kernel/include/itemreview.php"); - -class clsItemReview extends clsParsedItem -{ - function clsItemReview($ReviewId=NULL,$table="ItemReview") - { - $this->clsParsedItem(); - $this->tablename = $table; - $this->id_field = "ReviewId"; - $this->type=-20; - $this->NoResourceId=1; - $this->TagPrefix = "review"; - - if($ReviewId!=NULL) - $this->LoadFromDatabase($ReviewId); - } - - function Validate() - { - global $Errors; - - $dataValid = true; - if(!isset($this->m_CreatedOn)) - { - $Errors->AddError("error.fieldIsRequired",'CreatedOn',"","",get_class($this),"Validate"); - $dataValid = false; - } - - if(!isset($this->m_ReviewText)) - { - $Errors->AddError("error.fieldIsRequired",'ReviewText',"","",get_class($this),"Validate"); - $dataValid = false; - } - - if(!isset($this->m_Pending)) - { - $Error->AddError("error.fieldIsRequired",'Pending',"","",get_class($this),"Validate"); - $dataValid = false; - } - - if(!isset($this->m_IPAddress)) - { - $Error->AddError("error.fieldIsRequired",'IPAddress',"","",get_class($this),"Validate"); - $dataValid = false; - } - - if(!isset($this->m_ItemId)) - { - $Error->AddError("error.fieldIsRequired",'ItemId',"","",get_class($this),"Validate"); - $dataValid = false; - } - - if(!isset($this->m_CreatedById)) - { - $Error->AddError("error.fieldIsRequired",'CreatedBy',"","",get_class($this),"Validate"); - $dataValid = false; - } - - return $dataValid; - } - - function LoadFromDatabase($Id) - { - global $objSession, $Errors; - - if(!isset($Id)) - { - $Errors->AddError("error.AppError",NULL,'Internal error: LoadFromDatabase id',"",get_class($this),"LoadFromDatabase"); - return false; - } - - $sql = sprintf("SELECT * FROM ".$this->tablename." WHERE ReviewId = '%s'",$Id); - if( $GLOBALS['debuglevel'] ) echo $sql."
"; - $result = $this->adodbConnection->Execute($sql); - if ($result === false) - { - $Errors->AddError("error.DatabaseError",NULL,$this->adodbConnection->ErrorMsg(),"",get_class($this),"LoadFromDatabase"); - return false; - } - $data = $result->fields; - if(is_array($data)) - $this->SetFromArray($data); - $this->Clean(); - return TRUE; - } - - function MoveUp() - { - $this->Increment("Priority"); - } - - function MoveDown() - { - $this->Decrement("Priority"); - } - - function ParseObject($element) - { - global $objConfig, $objCatList, $rootURL, $objUsers; - - $extra_attribs = ExtraAttributes($element->attributes); - - if(strtolower($element->name)==$this->TagPrefix) - { - $field = strtolower($element->attributes["_field"]); - switch($field) - { - case "id": - /* - @field:review.id - @description: review id - */ - $ret = $this->Get("ReviewId"); - break; - case "item_id": - /* - @field:review.item_id - @description: ID of the item being reviewed - */ - $ret = inp_unescape($this->Get("ItemId")); - break; - case "text": - /* - @field:review.text - @description:Review text - */ - if($this->Get("TextFormat")==0 || $element->attribues["_textonly"]) - { - $ret = inp_escape($this->Get("ReviewText"),0); - } - else - { - $ret = $this->Get("ReviewText"); - } - break; - case "ip": - /* - @field:review.ip - @description:IP address of remote host submitting the review - */ - $ret = $this->Get("IPAddress"); - break; - case "pending": - /* - @field:review.pending - @description: Returns the review pening status - */ - $ret = $this->Get("Pending"); - break; - case "item_type": - /* - @field:review.item_type - @description:Returns the name of the reviewed item type - */ - $type =& $objItemTypes->GetItem($this->Get("ItemType")); - if(is_object($type)) - $ret = $type->Get("ItemName"); - break; - case "date": - /* - @field:review.date - @description:Returns the date/time the review was created - @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 - */ - $d = $this->Get("CreatedOn"); - if($element->attributes["_tz"]) - { - $d = GetLocalTime($d,$objSession->Get("tz")); - } - - $part = strtolower($element->attributes["_part"]); - if(strlen($part)) - { - $ret = ExtractDatePart($part,$d); - } - else - { - if($d<=0) - { - $ret = ""; - } - else - $ret = LangDate($d); - } - break; - case "reviewer": - /* - @field:revier.reviewer - @description:Parse a user tag for the user submitting the review - @attrib:_usertag::User tag to parse, defaults to the users login name - */ - $userfield = $element->attributes["_usertag"]; - if(!strlen($userfield)) - { - $userfield = "login"; - } - if($this->Get("CreatedById")>0) - { - $u =& $objUsers->GetItem($this->Get("CreatedById")); - $e = new clsHtmlTag(); - $e->name = $u->TagPrefix; - $e->attributes = $element->attributes; - $e->attributes["_field"] = $userfield; - $ret = $u->ParseObject($e); - } - else - if($userfield=="login") - $ret = "root"; - break; - default: - $tag = $this->TagPrefix."_".$field; - $ret = "Undefined: ".$tag->name; - break; - } - } - else - { - $ret = $element->Execute(); - } - return $ret; - } - - function parsetag($tag) - { - global $objConfig, $objUsers, $objItemTypes; - if(is_object($tag)) - { - $tagname = $tag->name; - } - else - $tagname = $tag; - switch($tagname) - { - case "review_id": - return $this->Get("ReviewId"); - break; - case "review_item_id": - return inp_unescape($this->Get("ItemId")); - break; - case "review_text": - return $this->Get("ReviewText"); - break; - case "review_ip_address": - return $this->Get("IPAddress"); - break; - case "review_pending": - return $this->Get("Pending"); - break; - case "review_item_type": - $type =& $objItemTypes->GetItem($this->Get("ItemType")); - $res = $type->Get("ItemName"); - return $res; - break; - case "review_created_date": - return LangDate($this->Get("CreatedOn")); - break; - case "review_created_time": - if($this->Get("CreatedOn")<=0) - return ""; - return adodb_date($objConfig->TimeFormat(), $this->Get("CreatedOn")); - break; - - case "review_created_date_month": - return adodb_date("m", $this->Get("CreatedOn")); - break; - case "review_created_date_day": - return adodb_date("d", $this->Get("CreatedOn")); - break; - case "review_created_date_year": - return adodb_date("Y", $this->Get("CreatedOn")); - break; - default: - if (substr($tagname, 0, 16) == "review_createdby") - { - /* parse the created by user */ - $u = $objUsers->GetUser($this->Get("CreatedById")); - $usertag = substr($tag,17); - return $u->parsetag($usertag); - } - else - return "Undefined:$tagname"; - break; - } - } - - function SendUserEventMail($Suffix,$ToUserId,$LangId=NULL) - { - global $objItemTypes, $objMessageList; - - $type =& $objItemTypes->GetItem($this->Get("ItemType")); - $res = $type->Get("ItemName"); - $EventName = $res.$Suffix; - - $Event =& $objMessageList->GetEmailEventObject($EventName,0,$LangId); - if(is_object($Event)) - { - if($Event->Get("Enabled")=="1") - { - $Event->Item = $this; - return $Event->SendToUser($ToUserId); - } - } - } - - function SendAdminEventMail($EventName,$LangId=NULL) - { - global $objItemTypes, $objMessageList; - - $type =& $objItemTypes->GetItem($this->Get("ItemType")); - $res = $type->Get("ItemName"); - $EventName = $res; //.$Suffix; - - $Event =& $objMessageList->GetEmailEventObject($EventName,1,$LangId); - if(is_object($Event)) - { - if($Event->Get("Enabled")=="1") - { - $Event->Item = $this; - return $Event->SendAdmin($ToUserId); - } - } - } -} /*clsIItemReview*/ - -class clsItemReviewList extends clsItemCollection -{ - var $itemID; - var $Page; - var $PerPageVar; - - function clsItemReviewList($id=NULL) - { - $this->clsItemCollection(); - $this->classname = "clsItemReview"; - $this->SourceTable = GetTablePrefix()."ItemReview"; - $this->Page = 1; - $this->PerPageVar = "Perpage_Review"; - if(isset($id)) - $this->itemID=$id; - $this->AdminSearchFields = array("ReviewText"); - } - - function ItemCount() - { - return $this->NumItems(); - } - - function GetReview($ID) - { - return $this->GetItem($ID); - } - - function GetReviewList($StatusWhere = "Status=1", $OrderBy=NULL) - { - $this->Clear(); - $where = "ItemId=".$this->itemID; - $sql = "SELECT * FROM ".$this->SourceTable." WHERE "; - if(strlen($StatusWhere)) - $where .= " AND ".$StatusWhere; - $sql .= $where; - if(strlen($OrderBy)) - $sql .= " ORDER BY ".$OrderBy; - $Limit = $this->GetLimitSQL(); - if(strlen($Limit)) - $sql .= " ".$Limit; - $this->QueryItemCount=TableCount($this->SourceTable,$where,0); - return $this->Query_item($sql); - } - - function GetItemReviewCount($TodayOnly = FALSE) - { - $sql = "SELECT count(*) as ItemCount FROM ".$this->SourceTable." WHERE ItemId=".$this->itemID." AND Status=1"; - if($TodayOnly) - { - $today = mktime(0,0,0,date("m"),date("d"),date("Y")); - $where .= " AND CreatedOn>=$today"; - } - $rs = $this->adodbConnection->execute($sql); - $count=0; - if($rs) - $count = $rs->fields["ItemCount"]; - return (int)$count; - } - - function ip_exists($ip,$id) - { - return ip_exists($ip,id,$this->SourceTable); - } - - function GetLimitSQL() - { - global $objConfig; - if($this->Page<1) - $this->Page=1; - $PerPage = $objConfig->Get($this->PerPageVar); - if(is_numeric($PerPage)) - { - $Start = ($this->Page-1)*$PerPage; - $limit = "LIMIT ".$Start.",".$PerPage; - } - else - $limit = NULL; - return $limit; - } - - - function Query_Review($whereClause=NULL,$orderByClause=NULL) - { - global $Errors; - - $this->Clear(); - $sql = "SELECT * FROM ".$this->SourceTable." "; - - if(isset($whereClause) && strlen(trim($whereClause))>0) - $sql = sprintf("%s WHERE %s",$sql,$whereClause); - - if(isset($orderByClause) && strlen(trim($orderByClause))>0) - $sql = sprintf("%s ORDER BY %s",$sql,$orderByClause); - - return $this->Query_Item($sql); - } - - function &AddReview($CreatedOn,$ReviewText, $Status, $IPAddress, - $Priority, $ItemId,$ItemType,$CreatedById,$TextFormat=0,$Module) - { - global $objSession; - - $r = new clsItemReview(NULL,$this->SourceTable); - - $ReviewText = str_replace("env=".$objSession->GetSessionKey(), "env=",$ReviewText); - //$r->debuglevel = 1; - - $r->Set(array("CreatedOn","ReviewText","Status", "IPAddress", - "Priority","ItemId","ItemType","CreatedById","TextFormat","Module"), - array($CreatedOn,$ReviewText,$Status, $IPAddress, - $Priority, $ItemId,$ItemType,$CreatedById,$TextFormat,$Module)); - $r->Create(); - array_push($this->Items,$r); - if($Status==1) - { - $r->SendUserEventMail("REVIEW.ADD",$CreatedById); - $r->SendAdminEventMail("REVIEW.ADD"); - } - else - { - $r->SendUserEventMail("REVIEW.ADD.PENDING",$CreatedById); - $r->SendAdminEventMail("REVIEW.ADD.PENDING"); - } - - return $r; - } - - function EditReview($ReviewId,$CreatedOn,$ReviewText, $Status, - $IPAddress, $Priority, $ItemId,$ItemType,$CreatedById,$TextFormat,$Module) - { - global $objSession; - - $r = $this->GetItem($ReviewId); - if($CreatedById==0) - $CreatedById = $r->Get("CreatedById"); - $r->Set(array("ReviewId","CreatedOn","ReviewText","Status", - "IPAddress", "Priority", "ItemId","ItemType","CreatedById","TextFormat","Module"), - array($ReviewId,$CreatedOn,$ReviewText,$Status, - $IPAddress, $Priority, $ItemId,$ItemType,$CreatedById,$TextFormat,$Module)); - $r->Update(); - //$r->SendUserEventMail("REVIEW.MODIFY",$objSession->Get("PortalUserId")); - $r->SendAdminEventMail("REVIEW.MODIFY"); - return $r; - } - - function DeleteReview($ReviewId) - { - $r = $this->GetItem($ReviewId); - $r->Delete(); - } - - function CopyToItemId($OldId,$NewId) - { - $this->Clear(); - $this->Query_Review("ItemId=$OldId",""); - if($this->NumItems()>0) - { - foreach($this->Items as $i) - { - $i->Set("ItemId",$NewId); - $i->UnsetIdField(); - $i->Create(); - } - } - } - - function CopyFromEditTable($ResourceId) - { - global $objSession; - //echo "ToLive [Reviews]
"; - $edit_table = $objSession->GetEditTable($this->SourceTable); - $idlist = array(); - $sql = "SELECT * FROM $edit_table"; - $this->Clear(); - // get all items in edit-table - $rs = $this->adodbConnection->Execute($sql); - while($rs && !$rs->EOF) - { - $data =& $rs->fields; - - $c = $this->AddItemFromArray($data); - - $c->Dirty(); - if($data["ReviewId"]>0) - { - $c->Update(); - } - else - { - $c->UnsetIdField(); - $c->Create(); - } - $idlist[] = $c->Get("ReviewId"); - $rs->MoveNext(); - } - //print_pre($idlist); - $sql = "DELETE FROM ".$this->SourceTable." WHERE ItemId=$ResourceId ".(count($idlist) > 0 ? "AND ReviewId NOT IN (".implode(",",$idlist).")" : ""); - //echo "DEL REVIEW SQL: $sql
"; - $this->adodbConnection->Execute($sql); - @$this->adodbConnection->Execute("DROP TABLE IF EXISTS ".$edit_table); - } - - - function GetPageLinkList(&$UpdateVar,$dest_template=NULL,$page = NULL,$PagesToList=10,$HideEmpty=TRUE) - { - global $objConfig, $var_list_update, $var_list; - - if(!strlen($page)) - $page = GetIndexURL(); - $PerPage = $objConfig->Get($this->PerPageVar); - if($PerPage<1) - $PerPage=20; - $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) - { - $UpdateVar["rp"] = $this->Page-$PagesToList; - $prev_url = $page."?env=".BuildEnv(); - $o .= "<<"; - } - - - for($p=$StartPage;$p<=$EndPage;$p++) - { - if($p!=$this->Page) - { - $UpdateVar["rp"]=$p; - $href = $page."?env=".BuildEnv(); - $o .= " $p "; - } - else - { - $o .= "$p"; - } - } - if($EndPage<$NumPages && $EndPage>0) - { - $UpdateVar["rp"]=$this->Page+$PagesToList; - $next_url = $page."?env=".BuildEnv(); - $o .= " >>"; - } - unset($UpdateVar,$var_list_update["t"] ); - return $o; - } - - -} /*clsItemReviewList*/ - -?> +Execute($sql); + if($rs) + { + $count = $rs->fields["DupCount"]; + } + return ($count>0); +} + +RegisterPrefix("clsItemReview","review","kernel/include/itemreview.php"); + +class clsItemReview extends clsParsedItem +{ + function clsItemReview($ReviewId=NULL,$table="ItemReview") + { + $this->clsParsedItem(); + $this->tablename = $table; + $this->id_field = "ReviewId"; + $this->type=-20; + $this->NoResourceId=1; + $this->TagPrefix = "review"; + + if($ReviewId!=NULL) + $this->LoadFromDatabase($ReviewId); + } + + function Validate() + { + global $Errors; + + $dataValid = true; + if(!isset($this->m_CreatedOn)) + { + $Errors->AddError("error.fieldIsRequired",'CreatedOn',"","",get_class($this),"Validate"); + $dataValid = false; + } + + if(!isset($this->m_ReviewText)) + { + $Errors->AddError("error.fieldIsRequired",'ReviewText',"","",get_class($this),"Validate"); + $dataValid = false; + } + + if(!isset($this->m_Pending)) + { + $Error->AddError("error.fieldIsRequired",'Pending',"","",get_class($this),"Validate"); + $dataValid = false; + } + + if(!isset($this->m_IPAddress)) + { + $Error->AddError("error.fieldIsRequired",'IPAddress',"","",get_class($this),"Validate"); + $dataValid = false; + } + + if(!isset($this->m_ItemId)) + { + $Error->AddError("error.fieldIsRequired",'ItemId',"","",get_class($this),"Validate"); + $dataValid = false; + } + + if(!isset($this->m_CreatedById)) + { + $Error->AddError("error.fieldIsRequired",'CreatedBy',"","",get_class($this),"Validate"); + $dataValid = false; + } + + return $dataValid; + } + + function LoadFromDatabase($Id) + { + global $objSession, $Errors; + + if(!isset($Id)) + { + $Errors->AddError("error.AppError",NULL,'Internal error: LoadFromDatabase id',"",get_class($this),"LoadFromDatabase"); + return false; + } + + $sql = sprintf("SELECT * FROM ".$this->tablename." WHERE ReviewId = '%s'",$Id); + if( $GLOBALS['debuglevel'] ) echo $sql."
"; + $result = $this->adodbConnection->Execute($sql); + if ($result === false) + { + $Errors->AddError("error.DatabaseError",NULL,$this->adodbConnection->ErrorMsg(),"",get_class($this),"LoadFromDatabase"); + return false; + } + $data = $result->fields; + if(is_array($data)) + $this->SetFromArray($data); + $this->Clean(); + return TRUE; + } + + function MoveUp() + { + $this->Increment("Priority"); + } + + function MoveDown() + { + $this->Decrement("Priority"); + } + + function ParseObject($element) + { + global $objConfig, $objCatList, $rootURL, $objUsers; + + $extra_attribs = ExtraAttributes($element->attributes); + + if(strtolower($element->name)==$this->TagPrefix) + { + $field = strtolower($element->attributes["_field"]); + switch($field) + { + case "id": + /* + @field:review.id + @description: review id + */ + $ret = $this->Get("ReviewId"); + break; + case "item_id": + /* + @field:review.item_id + @description: ID of the item being reviewed + */ + $ret = $this->Get("ItemId"); + break; + case "text": + /* + @field:review.text + @description:Review text + */ + if($this->Get("TextFormat")==0 || $element->attribues["_textonly"]) + { + $ret = inp_htmlize($this->Get("ReviewText")); + } + else + { + $ret = $this->Get("ReviewText"); + } + break; + case "ip": + /* + @field:review.ip + @description:IP address of remote host submitting the review + */ + $ret = $this->Get("IPAddress"); + break; + case "pending": + /* + @field:review.pending + @description: Returns the review pening status + */ + $ret = $this->Get("Pending"); + break; + case "item_type": + /* + @field:review.item_type + @description:Returns the name of the reviewed item type + */ + $type =& $objItemTypes->GetItem($this->Get("ItemType")); + if(is_object($type)) + $ret = $type->Get("ItemName"); + break; + case "date": + /* + @field:review.date + @description:Returns the date/time the review was created + @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 + */ + $d = $this->Get("CreatedOn"); + if($element->attributes["_tz"]) + { + $d = GetLocalTime($d,$objSession->Get("tz")); + } + + $part = strtolower($element->attributes["_part"]); + if(strlen($part)) + { + $ret = ExtractDatePart($part,$d); + } + else + { + if($d<=0) + { + $ret = ""; + } + else + $ret = LangDate($d); + } + break; + case "reviewer": + /* + @field:revier.reviewer + @description:Parse a user tag for the user submitting the review + @attrib:_usertag::User tag to parse, defaults to the users login name + */ + $userfield = $element->attributes["_usertag"]; + if(!strlen($userfield)) + { + $userfield = "login"; + } + if($this->Get("CreatedById")>0) + { + $u =& $objUsers->GetItem($this->Get("CreatedById")); + $e = new clsHtmlTag(); + $e->name = $u->TagPrefix; + $e->attributes = $element->attributes; + $e->attributes["_field"] = $userfield; + $ret = $u->ParseObject($e); + } + else + if($userfield=="login") + $ret = "root"; + break; + default: + $tag = $this->TagPrefix."_".$field; + $ret = "Undefined: ".$tag->name; + break; + } + } + else + { + $ret = $element->Execute(); + } + return $ret; + } + + function parsetag($tag) + { + global $objConfig, $objUsers, $objItemTypes; + if(is_object($tag)) + { + $tagname = $tag->name; + } + else + $tagname = $tag; + switch($tagname) + { + case "review_id": + return $this->Get("ReviewId"); + break; + case "review_item_id": + return $this->Get("ItemId"); + break; + case "review_text": + return $this->Get("ReviewText"); + break; + case "review_ip_address": + return $this->Get("IPAddress"); + break; + case "review_pending": + return $this->Get("Pending"); + break; + case "review_item_type": + $type =& $objItemTypes->GetItem($this->Get("ItemType")); + $res = $type->Get("ItemName"); + return $res; + break; + case "review_created_date": + return LangDate($this->Get("CreatedOn")); + break; + case "review_created_time": + if($this->Get("CreatedOn")<=0) + return ""; + return adodb_date($objConfig->TimeFormat(), $this->Get("CreatedOn")); + break; + + case "review_created_date_month": + return adodb_date("m", $this->Get("CreatedOn")); + break; + case "review_created_date_day": + return adodb_date("d", $this->Get("CreatedOn")); + break; + case "review_created_date_year": + return adodb_date("Y", $this->Get("CreatedOn")); + break; + default: + if (substr($tagname, 0, 16) == "review_createdby") + { + /* parse the created by user */ + $u = $objUsers->GetUser($this->Get("CreatedById")); + $usertag = substr($tag,17); + return $u->parsetag($usertag); + } + else + return "Undefined:$tagname"; + break; + } + } + + function SendUserEventMail($Suffix,$ToUserId,$LangId=NULL) + { + global $objItemTypes, $objMessageList; + + $type =& $objItemTypes->GetItem($this->Get("ItemType")); + $res = $type->Get("ItemName"); + $EventName = $res.$Suffix; + + $Event =& $objMessageList->GetEmailEventObject($EventName,0,$LangId); + if(is_object($Event)) + { + if($Event->Get("Enabled")=="1") + { + $Event->Item = $this; + return $Event->SendToUser($ToUserId); + } + } + } + + function SendAdminEventMail($EventName,$LangId=NULL) + { + global $objItemTypes, $objMessageList; + + $type =& $objItemTypes->GetItem($this->Get("ItemType")); + $res = $type->Get("ItemName"); + $EventName = $res; //.$Suffix; + + $Event =& $objMessageList->GetEmailEventObject($EventName,1,$LangId); + if(is_object($Event)) + { + if($Event->Get("Enabled")=="1") + { + $Event->Item = $this; + return $Event->SendAdmin($ToUserId); + } + } + } +} /*clsIItemReview*/ + +class clsItemReviewList extends clsItemCollection +{ + var $itemID; + var $Page; + var $PerPageVar; + + function clsItemReviewList($id=NULL) + { + $this->clsItemCollection(); + $this->classname = "clsItemReview"; + $this->SourceTable = GetTablePrefix()."ItemReview"; + $this->Page = 1; + $this->PerPageVar = "Perpage_Review"; + if(isset($id)) + $this->itemID=$id; + $this->AdminSearchFields = array("ReviewText"); + } + + function ItemCount() + { + return $this->NumItems(); + } + + function GetReview($ID) + { + return $this->GetItem($ID); + } + + function GetReviewList($StatusWhere = "Status=1", $OrderBy=NULL) + { + $this->Clear(); + $where = "ItemId=".$this->itemID; + $sql = "SELECT * FROM ".$this->SourceTable." WHERE "; + if(strlen($StatusWhere)) + $where .= " AND ".$StatusWhere; + $sql .= $where; + if(strlen($OrderBy)) + $sql .= " ORDER BY ".$OrderBy; + $Limit = $this->GetLimitSQL(); + if(strlen($Limit)) + $sql .= " ".$Limit; + $this->QueryItemCount=TableCount($this->SourceTable,$where,0); + return $this->Query_item($sql); + } + + function GetItemReviewCount($TodayOnly = FALSE) + { + $sql = "SELECT count(*) as ItemCount FROM ".$this->SourceTable." WHERE ItemId=".$this->itemID." AND Status=1"; + if($TodayOnly) + { + $today = mktime(0,0,0,date("m"),date("d"),date("Y")); + $where .= " AND CreatedOn>=$today"; + } + $rs = $this->adodbConnection->execute($sql); + $count=0; + if($rs) + $count = $rs->fields["ItemCount"]; + return (int)$count; + } + + function ip_exists($ip,$id) + { + return ip_exists($ip,id,$this->SourceTable); + } + + function GetLimitSQL() + { + global $objConfig; + if($this->Page<1) + $this->Page=1; + $PerPage = $objConfig->Get($this->PerPageVar); + if(is_numeric($PerPage)) + { + $Start = ($this->Page-1)*$PerPage; + $limit = "LIMIT ".$Start.",".$PerPage; + } + else + $limit = NULL; + return $limit; + } + + + function Query_Review($whereClause=NULL,$orderByClause=NULL) + { + global $Errors; + + $this->Clear(); + $sql = "SELECT * FROM ".$this->SourceTable." "; + + if(isset($whereClause) && strlen(trim($whereClause))>0) + $sql = sprintf("%s WHERE %s",$sql,$whereClause); + + if(isset($orderByClause) && strlen(trim($orderByClause))>0) + $sql = sprintf("%s ORDER BY %s",$sql,$orderByClause); + + return $this->Query_Item($sql); + } + + function &AddReview($CreatedOn,$ReviewText, $Status, $IPAddress, + $Priority, $ItemId,$ItemType,$CreatedById,$TextFormat=0,$Module) + { + global $objSession; + + $r = new clsItemReview(NULL,$this->SourceTable); + + $ReviewText = str_replace("env=".$objSession->GetSessionKey(), "env=",$ReviewText); + //$r->debuglevel = 1; + + $r->Set(array("CreatedOn","ReviewText","Status", "IPAddress", + "Priority","ItemId","ItemType","CreatedById","TextFormat","Module"), + array($CreatedOn,$ReviewText,$Status, $IPAddress, + $Priority, $ItemId,$ItemType,$CreatedById,$TextFormat,$Module)); + $r->Create(); + array_push($this->Items,$r); + if($Status==1) + { + $r->SendUserEventMail("REVIEW.ADD",$CreatedById); + $r->SendAdminEventMail("REVIEW.ADD"); + } + else + { + $r->SendUserEventMail("REVIEW.ADD.PENDING",$CreatedById); + $r->SendAdminEventMail("REVIEW.ADD.PENDING"); + } + + return $r; + } + + function EditReview($ReviewId,$CreatedOn,$ReviewText, $Status, + $IPAddress, $Priority, $ItemId,$ItemType,$CreatedById,$TextFormat,$Module) + { + global $objSession; + + $r = $this->GetItem($ReviewId); + if($CreatedById==0) + $CreatedById = $r->Get("CreatedById"); + $r->Set(array("ReviewId","CreatedOn","ReviewText","Status", + "IPAddress", "Priority", "ItemId","ItemType","CreatedById","TextFormat","Module"), + array($ReviewId,$CreatedOn,$ReviewText,$Status, + $IPAddress, $Priority, $ItemId,$ItemType,$CreatedById,$TextFormat,$Module)); + $r->Update(); + //$r->SendUserEventMail("REVIEW.MODIFY",$objSession->Get("PortalUserId")); + $r->SendAdminEventMail("REVIEW.MODIFY"); + return $r; + } + + function DeleteReview($ReviewId) + { + $r = $this->GetItem($ReviewId); + $r->Delete(); + } + + function CopyToItemId($OldId,$NewId) + { + $this->Clear(); + $this->Query_Review("ItemId=$OldId",""); + if($this->NumItems()>0) + { + foreach($this->Items as $i) + { + $i->Set("ItemId",$NewId); + $i->UnsetIdField(); + $i->Create(); + } + } + } + + function CopyFromEditTable($ResourceId) + { + global $objSession; + //echo "ToLive [Reviews]
"; + $edit_table = $objSession->GetEditTable($this->SourceTable); + $idlist = array(); + $sql = "SELECT * FROM $edit_table"; + $this->Clear(); + // get all items in edit-table + $rs = $this->adodbConnection->Execute($sql); + while($rs && !$rs->EOF) + { + $data =& $rs->fields; + + $c = $this->AddItemFromArray($data); + + $c->Dirty(); + if($data["ReviewId"]>0) + { + $c->Update(); + } + else + { + $c->UnsetIdField(); + $c->Create(); + } + $idlist[] = $c->Get("ReviewId"); + $rs->MoveNext(); + } + //print_pre($idlist); + $sql = "DELETE FROM ".$this->SourceTable." WHERE ItemId=$ResourceId ".(count($idlist) > 0 ? "AND ReviewId NOT IN (".implode(",",$idlist).")" : ""); + //echo "DEL REVIEW SQL: $sql
"; + $this->adodbConnection->Execute($sql); + @$this->adodbConnection->Execute("DROP TABLE IF EXISTS ".$edit_table); + } + + + function GetPageLinkList(&$UpdateVar,$dest_template=NULL,$page = NULL,$PagesToList=10,$HideEmpty=TRUE) + { + global $objConfig, $var_list_update, $var_list; + + if(!strlen($page)) + $page = GetIndexURL(); + $PerPage = $objConfig->Get($this->PerPageVar); + if($PerPage<1) + $PerPage=20; + $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) + { + $UpdateVar["rp"] = $this->Page-$PagesToList; + $prev_url = $page."?env=".BuildEnv(); + $o .= "<<"; + } + + + for($p=$StartPage;$p<=$EndPage;$p++) + { + if($p!=$this->Page) + { + $UpdateVar["rp"]=$p; + $href = $page."?env=".BuildEnv(); + $o .= " $p "; + } + else + { + $o .= "$p"; + } + } + if($EndPage<$NumPages && $EndPage>0) + { + $UpdateVar["rp"]=$this->Page+$PagesToList; + $next_url = $page."?env=".BuildEnv(); + $o .= " >>"; + } + unset($UpdateVar,$var_list_update["t"] ); + return $o; + } + + +} /*clsItemReviewList*/ + +?>