Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Mon, Mar 10, 7:10 AM

in-portal

Index: trunk/kernel/action.php
===================================================================
--- trunk/kernel/action.php (revision 899)
+++ trunk/kernel/action.php (revision 900)
@@ -1,2472 +1,2472 @@
<?php
$ro_perm = $objSession->HasSystemPermission("SYSTEM_ACCESS.READONLY");
// ====== Debugger related: begin ======
$script = basename($_SERVER['PATH_TRANSLATED']);
$skipDebug = Array('index.php','tree.php','head.php','credits.php');
if( admin_login() && !in_array($script, $skipDebug) )
{
if( IsDebugMode() )
{
if($Action) $debugger->setHTMLByIndex(1,'Kernel Action: <b>'.$Action.'</b>','append');
echo '<a href="javascript:self.location.reload();">Reload Frame</a> || ';
echo '<a href="javascript:toggleDebugLayer();">Show Debugger</a><br>';
}
}
unset($script, $skipDebug);
// ====== Debugger related: end ======
switch($Action)
{
case "m_save_import_config":
// Set New Import Category
if( GetVar('categorylist', true) !== false )
{
$cat_id = $_POST['categorylist'];
$objSession->SetVariable('categoryid', $cat_id);
if($cat_id > 0)
{
$cat = $objCatList->GetByResource($cat_id);
if(is_object($cat))
{
$navbar = $cat->Get('CachedNavbar');
$objSession->SetVariable('catnavbar', $navbar);
$objSession->SetVariable('import_category_id', $cat->UniqueId() );
}
}elseif($cat_id == 0)
{
global $objConfig;
$objSession->SetVariable('import_category_id', 0);
}
$objSession->SetVariable('categorylist', $_POST['categorylist']);
}
// Set Import Admin Group
if( GetVar('grouplist1', true) )
{
$group_id = $_POST['grouplist1'];
$group = $objGroups->GetItemByField('ResourceId',$group_id);
$objSession->SetVariable('user_admin_names', $group->Get('Name'));
$objSession->SetVariable('user_admin_values', $group->Get('GroupId'));
$objSession->SetVariable('grouplist1', $_POST['grouplist1']);
}
// Set Import User Group
if( GetVar('grouplist2', true) )
{
$group_id = $_POST['grouplist2'];
$group = $objGroups->GetItemByField('ResourceId', $group_id);
$objSession->SetVariable('user_regular_names', $group->Get('Name'));
$objSession->SetVariable('user_regular_values', $group->Get('GroupId'));
$objSession->SetVariable('grouplist2', $_POST['grouplist2']);
}
break;
case "m_add_user":
$dupe_user = '';
//$user_pending = (int)$_POST["user_pending"];
//$user_enabled = (int)$_POST["user_enabled"];
$CreatedOn = DateTimestamp($_POST["user_date"],GetDateFormat());
$CreatedOn += SecondsSinceMidnight($_POST["user_time"]);
$dob = DateTimestamp($_POST["user_dob"],GetDateFormat());
$objEditItems = new clsUserManager();
$objEditItems->SourceTable = $objSession->GetEditTable("PortalUser");
if(strlen($_POST["user_login"]))
$id = $objUsers->GetUserId($_POST["user_login"]);
else
$dob = 0;
if($id)
{
$lvErrorString = language('la_error_duplicate_username');
$dupe_user = $_POST["user_login"];
$_POST["user_login"] = '';
}
$password = md5($_POST["password"]);
$u = $objEditItems->Add_User($_POST["user_login"], $password,
$_POST["user_email"], $CreatedOn, $_POST["user_firstname"],
$_POST["user_lastname"], $_POST["status"],
$_POST["user_phone"],
$_POST["user_street"], $_POST["user_city"],
$_POST["user_state"], $_POST["user_zip"], $_POST["user_country"], $dob);
$objCustomEdit = new clsCustomDataList(); //$objSession->GetEditTable("CustomMetaData"));
$objCustomEdit->SetTable('edit');
$objCustomEdit->LoadResource($u->Get("ResourceId"));
$CustomFields = new clsCustomFieldList(6);
$DataChanged = FALSE;
foreach($_POST as $key=>$value)
{
if(substr($key,0,1)=="_")
{
$field = substr($key,1);
$cvalue = $CustomFields->GetItemByField("FieldName",$field,FALSE);
if(is_object($cvalue))
{
$objCustomEdit->SetFieldValue($cvalue->Get("CustomFieldId"),$u->Get("ResourceId"),$value);
$DataChanged = TRUE;
}
}
}
if($DataChanged) $objCustomEdit->SaveData();
$objCustomEdit->SetTable('live');
break;
case "m_edit_user":
//$CreatedOn = DateTimestamp($_POST["user_date"],GetDateFormat());
//$CreatedOn += SecondsSinceMidnight($_POST["user_time"]);
$dob = DateTimestamp($_POST["user_dob"],GetDateFormat());
$objEditItems = new clsUserManager();
$objEditItems->SourceTable = $objSession->GetEditTable("PortalUser");
//$user_pending = (int)$_POST["user_pending"];
//$user_enabled = (int)$_POST["user_enabled"];
$UserId = (int)$_POST["user_id"];
//echo $UserId."<br>\n";
if(!strlen($_POST["user_login"]))
$dob = 0;
if(strlen($_POST["password"]))
{
$password = md5($_POST["password"]);
}
else
$password = "";
$u = $objEditItems->Edit_User($UserId, $_POST["user_login"], $password,
$_POST["user_email"], $CreatedOn, $_POST["user_firstname"],
$_POST["user_lastname"], $_POST["status"],
$_POST["user_phone"],
$_POST["user_street"], $_POST["user_city"],
$_POST["user_state"], $_POST["user_zip"], $_POST["user_country"],
$dob);
$objCustomEdit = new clsCustomDataList(); //$objSession->GetEditTable("CustomMetaData"));
$objCustomEdit->SetTable('edit');
$DataChanged = false;
$objCustomEdit->LoadResource($u->Get("ResourceId"));
$CustomFields = new clsCustomFieldList(6);
foreach($_POST as $key=>$value)
{
if(substr($key,0,1)=="_")
{
$field = substr($key,1);
$cvalue = $CustomFields->GetItemByField("FieldName",$field,FALSE);
if(is_object($cvalue))
{
//echo "Saving CF: (".$cvalue->Get("CustomFieldId")." ; ".$u->Get("ResourceId")." ; $value)<br>";
$objCustomEdit->SetFieldValue($cvalue->Get("CustomFieldId"),$u->Get("ResourceId"),$value);
$DataChanged = TRUE;
}
}
}
if($DataChanged)
$objCustomEdit->SaveData();
$objCustomEdit->SetTable('live');
break;
case "m_user_primarygroup":
if($ro_perm) break;
$users = explode(',', $_POST["userlist"]);
$GroupResourceId = $_POST['grouplist'];
$g = $objGroups->GetItemByField("ResourceId", $GroupResourceId);
$GroupId = $g->UniqueId();
if( is_array($users) )
foreach($users as $user_id)
{
$u = $objUsers->GetItemByField("ResourceId", $user_id);
$g->AddUser($u->Get("PortalUserId"), 1);
}
break;
case "m_edit_group":
$objEditItems = new clsGroupList();
$objEditItems->SourceTable = $objSession->GetEditTable("PortalGroup");
$objEditItems->Edit_Group($_POST["group_id"], $_POST["group_name"],$_POST["group_comments"]);
break;
case "m_add_group":
$objEditItems = new clsGroupList();
$objEditItems->SourceTable = $objSession->GetEditTable("PortalGroup");
$objEditItems->Add_Group($_POST["group_name"], $_POST["group_comments"],0);
break;
case "m_group_sysperm":
if($ro_perm) break;
if($_POST["GroupEditStatus"]==0)
{
$objSession->ResetSysPermCache();
$GroupId = $_POST["GroupId"];
if($GroupId)
{
$objEditItems = new clsGroupList();
$objEditItems->SourceTable = $objSession->GetEditTable("PortalGroup");
$g = $objEditItems->GetItemByField("ResourceId",$GroupId);
if(is_object($g))
{
$PermList = explode(",",$_POST["PermList"]);
for($i=0;$i<count($PermList);$i++)
{
if(@in_array($PermList[$i],$_POST["inherit"]))
{
$value = -1;
}
else
{
$value = 0;
if(@in_array($PermList[$i],$_POST["permvalue"]))
$value = 1;
}
$g->SetSystemPermission($PermList[$i],$value);
}
}
}
}
break;
case "m_user_sysperm":
if($ro_perm) break;
if($_POST["UserEditStatus"]==0)
{
$UserId = $_POST["ItemId"];
if($UserId)
{
$objEditItems = new clsUserManager();
$objEditItems->SourceTable = $objSession->GetEditTable("PortalUser");
$u = $objEditItems->GetItemByField("ResourceId",$UserId);
unset($g);
if(is_object($u))
{
$objSession->ResetSysPermCache();
$g = $u->GetPersonalGroup(FALSE);
$PermList = explode(",",$_POST["PermList"]);
for($i=0;$i<count($PermList);$i++)
{
if(!@in_array($PermList[$i],$_POST["inherit"]))
{
if(!is_object($g))
$g = $u->GetPersonalGroup(TRUE);
$value = 0;
if(is_array($_POST["permvalue"]))
{
if(in_array($PermList[$i],$_POST["permvalue"]))
$value =1;
$g->SetSystemPermission($PermList[$i],$value);
}
else {
$g->SetSystemPermission($PermList[$i], 0);
}
}
else
{
if(is_object($g))
$g->SetSystemPermission($PermList[$i],-1);
}
}
}
}
}
break;
case "m_approve_user":
if($ro_perm) break;
foreach($_POST["itemlist"] as $userid)
{
$user = $objUsers->GetItemByField("ResourceId",$userid);
$user->Approve();
}
$objUsers->Clear();
break;
case "m_deny_user":
if($ro_perm) break;
foreach($_POST["itemlist"] as $userid)
{
$user = $objUsers->GetItemByField("ResourceId",$userid);
$user->Deny();
}
$objUsers->Clear();
break;
case "m_delete_user":
if($ro_perm) break;
foreach($_POST["itemlist"] as $userid)
$objUsers->Delete_User($userid);
break;
case "m_delete_group":
if($ro_perm) break;
foreach($_POST["itemlist"] as $groupid)
{
$objGroups->Delete_Group($groupid);
}
break;
case "m_user_assign": // not sure if action is used anywhere
if($ro_perm) break;
$useridlist = implode("-", $userlist);
$objSession->SetUserStatus($useridlist, "g_usergroup_status");
$g_usergroup_status = $useridlist;
break;
case "m_group_assign": // not sure if action is used anywhere
if($ro_perm) break;
foreach($grouplist as $group) $objGroups->Add_Users_To_Group($group);
break;
case "m_remove_group":
if($ro_perm) break;
$adodbConnection = &GetADODBConnection();
$adodbConnection->Execute("DELETE FROM UserGroup where UserId='$UserId' AND GroupId='$GroupId'");
break;
case "m_SetVariable":
$objSession->SetPersistantVariable($_POST["fieldname"], $_POST["varvalue"]);
break;
case "m_SetSessionVariable":
$objSession->SetVariable($_POST["fieldname"], $_POST["varvalue"]);
//echo "Setting $fieldname to $varvalue<br>\n";
if($_POST["fieldname"]=="SearchType")
$objSession->SetVariable("SearchWord","");
break;
case "m_edit_permissions":
if($ro_perm) break;
if($_POST["CatEditStatus"] != -1)
{
$objSession->SetVariable('PermCache_UpdateRequired', 1);
$GroupId = $_POST["GroupId"];
$CatId = $_POST["CategoryId"];
$Module = $_POST["Module"];
$ado = &GetADODBConnection();
$sql = "SELECT * FROM ".GetTablePrefix()."PermissionConfig WHERE ModuleId='$Module'";
$rs = $ado->Execute($sql);
$PermNames = array();
while($rs && !$rs->EOF)
{
$data = $rs->fields;
$PermNames[] = $data["PermissionName"];
$rs->MoveNext();
}
$inherit = array();
if(is_array($_POST["inherit"]))
{
foreach($_POST["inherit"] as $perm)
{
$inherit[$perm] = 1;
}
}
$access = array();
if(is_array($_POST["permvalue"]))
{
foreach($_POST["permvalue"] as $perm)
{
$access[$perm] = 1;
}
}
$objPermList = new clsPermList($CatId,$GroupId);
$objPermList->LoadCategory($CatId);
for($i=0;$i<count($PermNames);$i++)
{
if(!array_key_exists($PermNames[$i],$inherit))
{
$PermValue = (int)$access[$PermNames[$i]];
$Perm = $objPermList->GetPermByName($PermNames[$i]);
if($Perm)
{
$Id = $Perm->Get("PermissionId");
//echo "Editing $Id<br>\n";
$objPermList->Edit_Permission($Id,$CatId,$GroupId,$PermNames[$i],$PermValue,0);
}
else
{
//echo "Adding ".$PermNames[$i];
$objPermList->Add_Permission($CatId,$GroupId,$PermNames[$i],$PermValue,0);
}
}
else
{
$Perm = $objPermList->GetPermByName($PermNames[$i]);
if($Perm)
{
$Id = $Perm->Get("PermissionId");
$objPermList->Delete_Permission($Id);
}
}
}
//$c = $objCatList->GetItem($CatId);
//$glist = $objGroups->GetAllGroupList();
//$ViewList = $objPermList->GetGroupPermList($c,"CATEGORY.VIEW",$glist );
//$c->SetViewPerms("CATEGORY.VIEW",$ViewList,$glist);
//$c->Update();
}
break;
case "m_perm_delete_group":
if($ro_perm) break;
$ado = &GetADODBConnection();
$CatId = $_POST["CategoryId"];
foreach($_POST["itemlist"] as $groupid)
{
$g = $objGroups->GetItemByField("ResourceId",$groupid);
if(is_object($g))
{
$sql = "DELETE FROM ".GetTablePrefix()."Permissions WHERE CatId=$CatId AND GroupId=".$g->Get("GroupId");
if($objSession->HasSystemPermission("DEBUG.LIST"))
echo $sql."<br>\n";
$ado->Execute($sql);
}
}
break;
case "m_user_addto_group":
if($ro_perm) break;
$objSession->SetVariable("HasChanges", 1);
$user = $_POST["UserId"];
if(is_numeric($user))
{
if(strlen($_POST["grouplist"]))
{
$groups = explode(",",$_POST["grouplist"]);
if(is_array($groups))
{
for($i=0; $i<count($groups);$i++)
{
$g = $objGroups->GetItemByField("ResourceId",$groups[$i]);
$g->AddUser($user);
}
}
else
{
$g = $objGroups->GetItem($groups);
$g->AddUser($user);
}
}
}
break;
case "m_group_add_user":
if($ro_perm) break;
$objSession->SetVariable("HasChanges", 1);
$group = $_POST["GroupId"];
$EditGroups = new clsGroupList();
$EditGroups->SourceTable = $objSession->GetEditTable($objGroups->SourceTable);
$g = $EditGroups->GetItem($group);
// echo "Group: $group <br>\n";
if(is_numeric($group))
{
$users = explode(",",$_POST["userlist"]);
foreach($users as $userid)
{
$u = $objUsers->GetItemByField("ResourceId",$userid);
$g->AddUser($u->Get("PortalUserId"));
}
}
break;
case "m_group_removeuser":
if($ro_perm) break;
$objSession->SetVariable("HasChanges", 1);
$group = $_POST["GroupId"];
$g = $objGroups->GetItem($group);
//if($group>0)
//{
foreach($_POST["itemlist"] as $user_id)
{
$u = $objUsers->GetItemByField("ResourceId",$user_id);
$g->DeleteUser($u->Get("PortalUserId"));
}
//}
break;
case "m_user_removegroup":
if($ro_perm) break;
$objSession->SetVariable("HasChanges", 1);
$user = $_POST["UserId"];
//if($user>0)
//{
foreach($_POST["itemlist"] as $groupid)
{
$g = $objGroups->GetItem($groupid);
$g->DeleteUser($user);
}
//}
break;
case "m_sendmail":
if($ro_perm) break;
$idlist = explode(",",$_POST["idlist"]);
$html = (int)$_POST["html_enable"];
$body = inp_escape($_POST["email_body"],$html);
$subject = inp_escape($_POST["email_body"],$html);
$Email = new clsEmailMessage();
$Email->Set("Subject",$subject);
$Email->Set("Template",$body);
if($html)
$Email->Set("MessageType","HTML");
if(count($idlist)>0)
{
switch($_POST["IdType"])
{
case "group":
foreach($idlist as $id)
$Email->SendToGroup($id);
break;
case "user":
foreach($idlist as $id)
$Email->SendToUser($id);
break;
}/*switch*/
}
break;
case "m_item_recount":
if($ro_perm) break;
RunDown($m_var_list["cat"],"UpdateCacheCounts");
break;
case "m_cat_delete":
if($ro_perm) break;
if($objSession->HasCatPermission("CATEGORY.DELETE",$objCatList->CurrentCategoryID()))
{
if(isset($_POST["catlist"]))
{
if(is_array($_POST["catlist"]))
foreach($_POST["catlist"] as $catid)
{
$objCatList->Delete_Category($catid);
}
}
}
break;
case "m_cat_cut":
if($ro_perm) break;
if(isset($_POST["catlist"]))
{
if($objSession->HasCatPermission("CATEGORY.DELETE",$catid))
{
$objCatList->CopyToClipboard("CUT","CategoryId",$_POST["catlist"]);
}
else
$objCatList->CopyToClipboard("COPY","CategoryId",$_POST["catlist"]);
}
break;
case "m_cat_copy":
if($ro_perm) break;
if(isset($_POST["catlist"]))
{
$objCatList->CopyToClipboard("COPY","CategoryId",$_POST["catlist"]);
}
break;
case "m_paste":
if($ro_perm) break;
if($objCatList->ItemsOnClipboard()>0)
{
/* category's paste function populates a sparse array where array[old_id]=new_id */
$PastedCatIds = array();
$objCatList->PasteFromClipboard($objCatList->CurrentCategoryID(),"Name");
}
else
{
$clip = $objSession->GetVariable("ClipBoard");
if(strlen($clip))
{
$ClipBoard = ParseClipboard($clip);
$Action= strtolower($ClipBoard["table"])."_paste";
}
}
break;
case "m_cat_move_up":
if($ro_perm) break;
if (isset($_POST["catlist"]))
{
foreach($_POST["catlist"] as $catid)
{
$cat =& $objCatList->GetCategory($catid);
$cat->MoveUp();
}
}
break;
case "m_cat_move_down":
if($ro_perm) break;
if (isset($_POST["catlist"]))
{
$catlist=array_reverse($_POST["catlist"]);
foreach($catlist as $catid)
{
$cat =& $objCatList->GetCategory($catid);
$cat->MoveDown();
}
}
break;
case "m_cat_approve":
if($ro_perm) break;
if (isset($_POST["catlist"]))
{
foreach($_POST["catlist"] as $catid)
{
$cat =& $objCatList->GetCategory($catid);
$cat->Approve();
}
}
break;
case "m_cat_decline":
if($ro_perm) break;
if (isset($_POST["catlist"]))
{
foreach($_POST["catlist"] as $catid)
{
$cat =& $objCatList->GetCategory($catid);
//$cat->Deny();
RunDown($catid,"Deny");
}
}
break;
case "m_rel_delete":
$adodbConnection= &GetADODBConnection();
$table = $objSession->GetEditTable("Relationship");
if(isset($_POST["itemlist"]))
{
if(is_array($_POST["itemlist"]))
{
foreach($_POST["itemlist"] as $id)
{
$sql = "DELETE FROM ".$table." WHERE RelationshipId=".$id;
$adodbConnection->Execute($sql);
if($objSession->HasSystemPermission("DEBUG.LIST"))
echo $sql."<br>\n";
}
}
else
{
$sql = "DELETE FROM ".$table." WHERE RelationshipId=".$_POST["itemlist"];
$adodbConnection->Execute($sql);
if($objSession->HasSystemPermission("DEBUG.LIST"))
echo $sql."<br>\n";
}
}
break;
case "m_add_relation":
$RelList = new clsRelationshipList();
$RelList->SourceTable = $objSession->GetEditTable("Relationship");
//$r = $RelList->Add($_POST["SourceId"],$_POST["SourceType"],$_POST["TargetId"],$_POST["TargetType"],
// 0,(int)$_POST["Enabled"],$_POST["RelType"], $Rel);
$ado = &GetADODBConnection();
$NewId = intval($ado->GetOne('SELECT MIN(RelationshipId) as MinValue FROM '.$RelList->SourceTable));
if($NewId > 0) $NewId = 0;
$NewId--;
$r = $RelList->Add($_POST["SourceId"],$_POST["SourceType"],$_POST["TargetId"],$_POST["TargetType"],
0,(int)$_POST["Enabled"],$_POST["RelType"], $NewId);
$sql = "UPDATE ".$RelList->SourceTable." SET RelationshipId=".$NewId." WHERE RelationshipId=".$r->Get("RelationshipId");
if($objSession->HasSystemPermission("DEBUG.LIST"))
echo $sql."<br>\n";
$ado->Execute($sql);
break;
case "m_edit_relation":
if($_POST["CatEditStatus"]==0)
{
$RelList = new clsRelationshipList();
$RelList->SourceTable = $objSession->GetEditTable("Relationship");
$r = $RelList->GetItem($_POST["RelationshipId"]);
if(is_object($r))
{
$r->Set("Enabled",(int)$_POST["Enabled"]);
$r->Set("Type",(int)$_POST["RelType"]);
$r->Set("Priority",(int)$_POST["priority"]);
$r->Update();
}
}
break;
case "m_rel_move_up":
$objRelList = new clsRelationshipList();
$objRelList->SourceTable = $objSession->GetEditTable("Relationship");
if (isset($_POST["itemlist"]))
{
foreach($_POST["itemlist"] as $id)
{
$r = $objRelList->GetItem($id);
$r->MoveUp($_POST["SourceId"]);
}
}
break;
case "m_rel_move_down":
$objRelList = new clsRelationshipList();
$objRelList->SourceTable = $objSession->GetEditTable("Relationship");
if (isset($_POST["itemlist"]))
{
$itemlist=array_reverse($_POST["itemlist"]);
foreach($itemlist as $id)
{
$r = $objRelList->GetItem($id);
$r->MoveDown($_POST["SourceId"]);
}
}
break;
case "m_add_category":
if(ValidDate($_POST["cat_date"],GetDateFormat()))
{
$CreatedOn = DateTimestamp($_POST["cat_date"],GetDateFormat());
}
else
$CreatedOn = time();
$html = (int)$_POST["html_enable"];
$cat_pick = $_POST["cat_pick"];
$Status = (int)$_POST["status"];
$Hot=(int)$_POST["itemhot"];
$Pop = (int)$_POST["itempop"];
$New = (int)$_POST["itemnew"];
$objEditItems = new clsCatList();
$objEditItems->SourceTable = $objSession->GetEditTable("Category");
$cat = $objEditItems->Add($_POST["ParentId"], $_POST["cat_name"], inp_escape($_POST["cat_desc"],$html), $CreatedOn,
$cat_pick, $Status, $Hot, $New, $Pop, $_POST["Priority"],
$_POST["meta_keywords"],$_POST["meta_desc"]);
$objCustomEdit = new clsCustomDataList($objSession->GetEditTable("CustomMetaData"));
$objCustomEdit->LoadResource($cat->Get("ResourceId"));
$CustomFields = new clsCustomFieldList(1);
$DataChanged = FALSE;
foreach($_POST as $key=>$value)
{
if(substr($key,0,1)=="_")
{
$field = substr($key,1);
$cvalue = $CustomFields->GetItemByField("FieldName",$field,FALSE);
if(is_object($cvalue))
{
$objCustomEdit->SetFieldValue($cvalue->Get("CustomFieldId"),$cat->Get("ResourceId"),$value);
$DataChanged = TRUE;
}
}
}
if($DataChanged)
$objCustomEdit->SaveData();
break;
case "m_edit_category":
$CreatedOn = DateTimestamp($_POST["cat_date"],GetDateFormat());
$cat_pick = GetVar('cat_pick', true);
$Status = (int)$_POST["status"];
$Hot = false; //(int)$_POST["itemhot"];
$Pop = false; //(int)$_POST["itempop"];
$New = (int)$_POST["itemnew"];
$html = (int)$_POST["html_enable"];
$objEditItems = new clsCatList();
$objEditItems->SourceTable = $objSession->GetEditTable("Category");
// check if name of cat isn't changed: begin
if( GetVar('CategoryId') > 0 )
{
$original_cats = new clsCatList();
$original_cat = $original_cats->GetItemByField('CategoryId', GetVar('CategoryId'));
if( $original_cat->Get('Name') != stripslashes($_POST['cat_name'] ))
$objSession->SetVariable('PermCache_UpdateRequired', 1);
unset($original_cat, $original_cats);
}
else
{
$objSession->SetVariable('PermCache_UpdateRequired', 1);
}
// check if name of cat isn't changed: end
$cat = $objEditItems->Edit_Category($_POST["CategoryId"],inp_escape($_POST["cat_name"],$html), inp_escape($_POST["cat_desc"],$html), $CreatedOn, $cat_pick, $Status, $Hot, $New, $Pop, $_POST["Priority"], $_POST["meta_keywords"], $_POST["meta_desc"]);
$objCustomEdit = new clsCustomDataList($objSession->GetEditTable("CustomMetaData"));
$objCustomEdit->LoadResource($cat->Get("ResourceId"));
$CustomFields = new clsCustomFieldList(1);
$DataChanged = FALSE;
foreach($_POST as $key=>$value)
{
if(substr($key,0,1)=="_")
{
$field = substr($key,1);
$cvalue = $CustomFields->GetItemByField("FieldName",$field,FALSE);
if(is_object($cvalue))
{
$objCustomEdit->SetFieldValue($cvalue->Get("CustomFieldId"),$cat->Get("ResourceId"),$value);
$DataChanged = TRUE;
}
}
}
if($DataChanged)
$objCustomEdit->SaveData();
break;
case "m_edit_custom_data":
$id = $_POST["ItemId"];
$objCustomEdit = new clsCustomDataList($objSession->GetEditTable("CustomMetaData"));
$objCustomEdit->LoadResource($id);
$CustomFields = new clsCustomFieldList($_POST['CustomType']);
$DataChanged = FALSE;
foreach($_POST as $key=>$value)
{
if(substr($key,0,1)=="_")
{
$field = substr($key,1);
$cvalue = $CustomFields->GetItemByField("FieldName",$field,FALSE);
if(is_object($cvalue))
{
$objCustomEdit->SetFieldValue($cvalue->Get("CustomFieldId"),$id,$value);
$DataChanged = TRUE;
}
}
}
if($DataChanged)
$objCustomEdit->SaveData();
/*
$id = $_POST["ItemId"];
$objEditData = new clsCustomDataList(); //$objSession->GetEditTable("CustomMetaData"));
$objEditData->SetTable('edit');
$ado = &GetADODBConnection();
if($id && is_array($_POST["CustomData"]))
{
foreach($_POST["CustomData"] as $FieldId => $Value)
{
$sql = "SELECT count(*) as reccount FROM ".$objEditData->SourceTable." WHERE CustomFieldId=$FieldId AND ResourceId=".$_POST["ItemId"];
$rs = $ado->Execute($sql);
$intable = $rs->fields["reccount"];
if(!$intable)
{
$sql = "INSERT INTO ".$objEditData->SourceTable." (ResourceId,CustomFieldId,Value) VALUES ('".$id."','$FieldId','$Value')";
$ado->Execute($sql);
//echo $sql."<br>\n";
}
else
{
$sql = "UPDATE ".$objEditData->SourceTable." SET Value='".$Value."' WHERE CustomFieldId=$FieldId AND ResourceId=".$_POST["ItemId"];
$ado->Execute($sql);
//echo $sql."<br>\n";
}
}
}
$objEditData->SetTable('live');
*/
break;
case "m_customfield_edit":
if($ro_perm) break;
$DataType = $_POST["DataType"];
$FieldId = $_POST["CustomFieldId"];
$FieldName = $_POST["fieldname"];
//$FieldLabel = $_POST["fieldlabel"];
if(strlen($FieldName))
{
$objCustomFields = new clsCustomFieldList($DataType);
$objCustomFields->EditField($FieldId,$DataType,$FieldName,"",(int)$_POST["generaltab"],
$_POST["heading"],$_POST["fieldprompt"],$_POST["input_type"],
$_POST["valuelist"]);
}
unset($objCustomFields);
break;
case "m_customfield_add":
if($ro_perm) break;
$DataType = $_POST["DataType"];
$FieldName = $_POST["fieldname"];
//$FieldLabel = $_POST["fieldlabel"];
if(strlen($FieldName))
{
$objCustomFields = new clsCustomFieldList($DataType);
$objCustomFields->AddField($DataType,$FieldName,"",(int)$_POST["generaltab"],
$_POST["heading"],$_POST["fieldprompt"],$_POST["input_type"],
$_POST["valuelist"]);
unset($objCustomFields);
}
break;
case "m_customfield_delete":
if($ro_perm) break;
$DataType = $_POST["DataType"];
$objCustomFields = new clsCustomFieldList($DataType);
foreach($_POST["itemlist"] as $f)
{
$objCustomFields->DeleteField($f);
//$c = $objCustomFields->GetItem($f);
//$c->Delete();
}
unset($objCustomFields);
break;
case "m_SearchConfig_Edit":
if($ro_perm) break;
$SimpleValues = $_POST["simple"];
$AdvValues = $_POST["advanced"];
$module = $_POST["module"];
$priority = $_POST["pri"];
//phpinfo(INFO_VARIABLES);
$objSearchConfig = new clsSearchConfigList($module);
foreach($objSearchConfig->Items as $i)
{
$id = $i->Get("SearchConfigId");
$objSearchConfig->EditFieldSettings($id,(int)$SimpleValues[$id],(int)$AdvValues[$id],$priority[$id]);
}
$objSearchConfig->Clear();
/* save relevence settings */
$vals = $_POST["req_increase"];
foreach($vals as $var=>$value)
{
$cfg = "SearchRel_Increase_".$var;
$objConfig->Set($cfg,$value);
}
$vals = $_POST["rel_keyword"];
foreach($vals as $var=>$value)
{
$cfg = "SearchRel_Keyword_".$var;
$objConfig->Set($cfg,$value);
}
$vals = $_POST["rel_pop"];
foreach($vals as $var=>$value)
{
$cfg = "SearchRel_Pop_".$var;
$objConfig->Set($cfg,$value);
}
$vals = $_POST["rel_rating"];
foreach($vals as $var=>$value)
{
$cfg = "SearchRel_Rating_".$var;
$objConfig->Set($cfg,$value);
}
$vals = $_POST["multiple"];
if (count($vals) > 0) {
foreach($vals as $var=>$value)
{
$cfg = "Search_ShowMultiple_".$var;
$objConfig->Set($cfg,$value);
}
}
else {
$cfg = "Search_ShowMultiple_".$_POST['cfg_var'];
$objConfig->Set($cfg, 0);
}
if (isset($_POST['minkeyword'])) {
$objConfig->Set("Search_MinKeyword_Length", $_POST['minkeyword']);
}
$objConfig->Save();
break;
case "m_keyword_reset":
if($ro_perm) break;
$objSearchList = new clsSearchLogList();
foreach($_POST["itemlist"] as $k)
{
$c = $objSearchList->GetItem($k);
$c->Delete();
}
break;
case "m_review_add":
$post_info = GetSubmitVariable($_POST, 'EditStatus');
if($post_info['variable'] > -1)
{
$objReviews = new clsItemReviewList();
$objReviews->SourceTable = $objSession->GetEditTable("ItemReview");
$Pending = (int)$_POST["review_pending"];
$Enabled = (int)$_POST["review_enabled"];
$Status = (int)$_POST["status"];
$CreatedOn = DateTimestamp($_POST["review_date"],GetDateFormat());
$CreatedOn += SecondsSinceMidnight($_POST["review_time"]);
$html = (int)$_POST["html_enable"];
$ReviewText = inp_escape($_POST["review_body"],1);
$CreatedById = 0;
if(strlen($_POST["createdby"])>0)
{
if(strtolower($_POST["createdby"])=="root")
{
$CreatedById = -1;
}
else
{
$u = $objUsers->GetItemByField("Login",$_POST["createdby"]);
if(is_object($u))
{
$CreatedById = $u->Get("PortalUserId");
if($CreatedById<1)
{
$CreatedById = $objSession->Get("PortalUserId");
}
}
else
$CreatedById = $objSession->Get("PortalUserId");
}
}
else
$CreatedById = $objSession->Get("PortalUserId");
$r = $objReviews->AddReview($CreatedOn,$ReviewText,$Status, $IPAddress,
(int)$_POST["review_priority"], $_POST["ItemId"],$_POST["ItemType"],
$CreatedById,$html, $post_info['Module']);
$ado = &GetADODBConnection();
$rs = $ado->Execute("SELECT MIN(ReviewId) as MinValue FROM ".$objReviews->SourceTable);
$NewId = $rs->fields["MinValue"]-1;
$sql = "UPDATE ".$objReviews->SourceTable." SET ReviewId=".$NewId." WHERE ReviewId=".$r->Get("ReviewId");
if($objSession->HasSystemPermission("DEBUG.LIST"))
echo $sql."<br>\n";
$ado->Execute($sql);
}
break;
case "m_review_edit":
$post_info = GetSubmitVariable($_POST, 'EditStatus');
if($post_info['variable'] > -1)
{
$objReviews = new clsItemReviewList();
$objReviews->SourceTable = $objSession->GetEditTable("ItemReview");
$Status = (int)$_POST["status"];
$CreatedOn = DateTimestamp($_POST["review_date"],GetDateFormat());
$CreatedOn += SecondsSinceMidnight($_POST["review_time"]);
$html = (int)$_POST["html_enable"];
$ReviewText = inp_escape($_POST["review_body"],1);
$ReviewId = $_POST["ReviewId"];
$CreatedById = 0;
if(strlen($_POST["createdby"])>0)
{
if(strtolower($_POST["createdby"])=="root")
{
$CreatedById = -1;
}
else
{
$u = $objUsers->GetItemByField("Login",$_POST["createdby"]);
if(is_object($u))
{
$CreatedById = $u->Get("PortalUserId");
if($CreatedById<1)
{
$CreatedById = $objSession->Get("PortalUserId");
}
}
else
$CreatedById = $objSession->Get("PortalUserId");
}
}
$r = $objReviews->EditReview($ReviewId,$CreatedOn,$ReviewText,$Status, $IPAddress,
(int)$_POST["review_priority"],$_POST["ItemId"],$_POST["ItemType"],
$CreatedById,$html, $post_info['Module']);
}
break;
case "m_review_delete":
$objReviews = new clsItemReviewList();
$objReviews->SourceTable = $objSession->GetEditTable("ItemReview");
foreach($_POST["itemlist"] as $id)
{
$objReviews->DeleteReview($id);
}
break;
case "m_review_approve":
if (isset($_POST["itemlist"]))
{
$objReviews = new clsItemReviewList();
$objReviews->SourceTable = $objSession->GetEditTable("ItemReview");
foreach($_POST["itemlist"] as $id)
{
$i = $objReviews->GetItem($id);
$i->Set("Status",1);
$i->Update();
}
}
break;
case "m_review_deny":
if (isset($_POST["itemlist"]))
{
$objReviews = new clsItemReviewList();
$objReviews->SourceTable = $objSession->GetEditTable("ItemReview");
foreach($_POST["itemlist"] as $id)
{
$i = $objReviews->GetItem($id);
$i->Set("Status",0);
$i->Update();
}
}
break;
case "m_review_move_up":
if (isset($_POST["itemlist"]))
{
$objReviews = new clsItemReviewList();
$objReviews->SourceTable = $objSession->GetEditTable("ItemReview");
foreach($_POST["itemlist"] as $id)
{
$i = $objReviews->GetItem($id);
$i->MoveUp();
}
}
break;
case "m_review_move_down":
if (isset($_POST["itemlist"]))
{
$objReviews = new clsItemReviewList();
$objReviews->SourceTable = $objSession->GetEditTable("ItemReview");
$itemlist=array_reverse($_POST["itemlist"]);
foreach($itemlist as $id)
{
$i = $objReviews->GetItem($id);
$i->MoveDown();
}
}
break;
case "m_theme_add":
$ado = &GetADODBConnection();
$rs = $ado->Execute("SELECT COUNT(*) as c FROM ".GetTablePrefix().'Theme WHERE Name="'.$_POST["name"].'"');
if(!$rs->fields["c"])
{
$objEditItems = new clsThemeList();
$objEditItems->SourceTable = $objSession->GetEditTable("Theme");
$Primary = (int)$_POST["primary"];
if(!(int)$_POST["enabled"])
$Primary = 0;
$t = $objEditItems->AddTheme($_POST["name"],$_POST["description"],(int)$_POST["enabled"],$Primary,
(int)$_POST["CacheTimeout"]);
$t->Files->ThemeId=$t->Get("ThemeId");
$rs = $ado->Execute("SELECT MIN(ThemeId) as MinValue FROM ".$objEditItems->SourceTable);
$NewId = $rs->fields["MinValue"]-1;
$sql = "UPDATE ".$objEditItems->SourceTable." SET ThemeId=".$NewId." WHERE ThemeId=".$t->Get("ThemeId");
if($objSession->HasSystemPermission("DEBUG.LIST"))
echo $sql."<br>\n";
$ado->Execute($sql);
}
break;
case "m_theme_edit":
$objEditItems = new clsThemeList();
$objEditItems->SourceTable = $objSession->GetEditTable("Theme");
$Primary = (int)$_POST["primary"];
if(!(int)$_POST["enabled"])
$Primary = 0;
$objEditItems->EditTheme($_POST["ThemeId"],$_POST["name"],$_POST["description"],
(int)$_POST["enabled"],$Primary,(int)$_POST["CacheTimeout"]);
// if ($Primary==1)
// {
// $objEditItems->SetPrimaryTheme($_POST["ThemeId"]);
// }
break;
case "m_theme_delete":
if($ro_perm) break;
if (isset($_POST["itemlist"]))
{
$Themes = new clsThemeList();
foreach($_POST["itemlist"] as $id)
{
$Themes->DeleteTheme($id);
}
}
break;
case "m_theme_primary":
if($ro_perm) break;
if( count($_POST['itemlist']) )
{
$ThemeId = array_shift( $_POST['itemlist'] );
$t = new clsThemeList();
$t->SetPrimaryTheme($ThemeId);
}
break;
case "m_template_edit":
if($ro_perm) break;
$objSession->SetVariable("HasChanges", 1);
$ThemeId = $_POST["ThemeId"];
$FileId = $_POST["FileId"];
$f = new clsThemeFile($FileId);
$f->Set("Description", $_POST["Description"] );
$f->Update();
$c = stripslashes($_POST["contents"]);
$f->SaveFileContents($c);
break;
case "m_template_add":
if($ro_perm) break;
$objSession->SetVariable("HasChanges", 1);
$ThemeId = $_POST["ThemeId"];
if( !is_object($f) ) $f = new clsThemeFile();
$FilePath = $_POST['name'];
if(!$FilePath)
{
$f->SetError('Template Name is required',3);
break;
}
else
{
if( substr($FilePath,1) != '/' ) $FilePath = '/'.$FilePath;
if( substr($FilePath,-3) != '.tpl' ) $FilePath .= '.tpl';
$FileName = basename($FilePath);
$FilePath = dirname($FilePath);
// test if such file not already created
$f->LoadFromDataBase( Array($FilePath,$FileName), Array('FilePath','FileName') );
if( !$f->Get('FileId') )
{
$f->Set( Array('FilePath','FileName','ThemeId', 'Description'),
Array($FilePath, $FileName,$_POST['ThemeId'], $_POST["Description"])
);
if( $f->IsWriteablePath(true) )
{
$f->Create();
$c = stripslashes($_POST["contents"]);
$f->SaveFileContents($c, true);
}
}
else
$f->SetError('Template with this name already exists',4);
}
break;
case "m_template_delete":
if($ro_perm) break;
$objSession->SetVariable("HasChanges", 1);
$dummy = new clsThemeFile();
foreach($_POST["itemlist"] as $FileId)
{
$dummy->LoadFromDatabase($FileId);
$dummy->Delete();
}
break;
case "m_lang_add":
$objEditItems = new clsLanguageList();
$objEditItems->SourceTable = $objSession->GetEditTable("Language");
$l = $objEditItems->AddLanguage($_POST["packname"],$_POST["localname"],
(int)$_POST["enabled"],(int)$_POST["primary"],
$_POST["icon"],$_POST["date_format"],$_POST["time_format"],
$_POST["decimal"],$_POST["thousand"]);
$ado = &GetADODBConnection();
$rs = $ado->Execute("SELECT MIN(LanguageId) as MinValue FROM ".$objEditItems->SourceTable);
$NewId = $rs->fields["MinValue"]-1;
$sql = "UPDATE ".$objEditItems->SourceTable." SET LanguageId=".$NewId." WHERE LanguageId=".$l->Get("LanguageId");
if($objSession->HasSystemPermission("DEBUG.LIST"))
echo $sql."<br>\n";
$ado->Execute($sql);
if($_POST["importlabels"]==1 && $_POST["srcpack"]>0)
{
// Phrase import
/*
$sql = "SELECT * FROM ".GetTablePrefix()."Phrase WHERE LanguageId=".$_POST["srcpack"];
if($objSession->HasSystemPermission("DEBUG.LIST"))
echo $sql."<br>\n";
$rs = $ado->Execute($sql);
$plist = new clsPhraseList();
$plist->SourceTable = $objSession->GetEditTable("Phrase");
$sql = "SELECT MIN(PhraseId) as MinId FROM ".$plist->SourceTable;
$as = $ado->Execute($sql);
if($as && !$as->EOF)
{
$MinId = (int)$as->fields["MinId"];
}
else
$MinId = 0;
$MinId--;
while($rs && !$rs->EOF)
{
$data = $rs->fields;
$plist->AddPhrase($data["Phrase"],$NewId,$data["Translation"],$data["PhraseType"]);
$sql = "UPDATE ".$plist->SourceTable." SET PhraseId=$MinId WHERE PhraseId=0 LIMIT 1";
$ado->Execute($sql);
$MinId--;
$rs->MoveNext();
}
*/
$sql='INSERT INTO '.$objSession->GetEditTable('Phrase').' SELECT Phrase, Translation, PhraseType, 0-PhraseId, '.$NewId.' FROM '.GetTablePrefix().'Phrase WHERE LanguageId='.$_POST['srcpack'];
$ado->Execute($sql);
// Events import
$sql = "SELECT * FROM ".GetTablePrefix()."EmailMessage WHERE LanguageId=".$_POST["srcpack"];
if($objSession->HasSystemPermission("DEBUG.LIST"))
echo $sql."<br>\n";
$rs = $ado->Execute($sql);
$eList = new clsEmailMessageList();
//$eList->SourceTable = $objSession->GetEditTable("EmailMessage");
if (!$l->TableExists($objSession->GetEditTable("EmailMessage"))) {
$eList->CreateEmptyEditTable("EmailMessageId", true);
$eList->SourceTable = $objSession->GetEditTable("EmailMessage");
}
else {
$eList->SourceTable = $objSession->GetEditTable("EmailMessage");
}
$sql = "SELECT MIN(EmailMessageId) as MinId FROM ".$eList->SourceTable;
$as = $ado->Execute($sql);
if($as && !$as->EOF)
{
$MinId = (int)$as->fields["MinId"];
}
else {
$MinId = 0;
}
$MinId--;
while($rs && !$rs->EOF)
{
$data = $rs->fields;
$eList->AddEmailEvent($data["Template"], $data["MessageType"], $NewId, $data["EventId"]);
$sql = "UPDATE ".$eList->SourceTable." SET EmailMessageId=$MinId WHERE EmailMessageId=0 LIMIT 1";
$ado->Execute($sql);
$MinId--;
$rs->MoveNext();
}
}
break;
case "m_lang_export":
if($ro_perm) break;
include_once($pathtoroot."kernel/include/xml.php");
$Ids = $_POST["LangList"]; // language ids list to export phrases from
$phrase_types = GetVar('langtypes');
$phrase_types = ($phrase_types !== false) ? implode(',',$phrase_types) : null;
$filename=$_POST["filename"];
if(strlen($filename)>0)
{
$ExportFilename = $pathtoroot.$admin."/export/".$filename;
$ExportResult = $objLanguages->ExportPhrases($ExportFilename,$Ids, $phrase_types);
}
break;
case "m_lang_edit":
$objEditItems = new clsLanguageList();
$objEditItems->SourceTable = $objSession->GetEditTable("Language");
$objEditItems->EditLanguage($_POST["LanguageId"],$_POST["packname"],
$_POST["localname"],(int)$_POST["enabled"],
(int)$_POST["primary"], $_POST["icon"],$_POST["date_format"],
$_POST["time_format"], $_POST["decimal"],$_POST["thousand"],
$_POST['charset']);
if($_POST["importlabels"]==1 && $_POST["srcpack"]>0)
{
$ado = &GetADODBConnection();
$rs = $ado->Execute("SELECT * FROM ".GetTablePrefix()."Phrase WHERE LanguageId=".$_POST["srcpack"]);
$plist = new clsPhraseList();
$plist->SourceTable = $objSession->GetEditTable("Phrase");
$sql = "SELECT MIN(PhraseId) as MinId FROM ".$plist->SourceTable;
$as = $ado->Execute($sql);
if($as && !$as->EOF)
{
$MinId = (int)$as->fields["MinId"];
}
else
$MinId = 0;
$MinId--;
while($rs && !$rs->EOF)
{
$data = $rs->fields;
$plist->AddPhrase($data["Phrase"],$_POST["LanguageId"],$data["Translation"],$data["PhraseType"]);
$sql = "UPDATE ".$plist->SourceTable." SET PhraseId=$MinId WHERE PhraseId=0 LIMIT 1";
$ado->Execute($sql);
$MinId--;
$rs->MoveNext();
}
unset($plist);
// Events import
$sql = "SELECT * FROM ".GetTablePrefix()."EmailMessage WHERE LanguageId=".$_POST["srcpack"];
if($objSession->HasSystemPermission("DEBUG.LIST"))
echo $sql."<br>\n";
$rs = $ado->Execute($sql);
$eList = new clsEmailMessageList();
//$eList->SourceTable = $objSession->GetEditTable("EmailMessage");
$l = new clsEmailMessage();
if (!$l->TableExists($objSession->GetEditTable("EmailMessage"))) {
$eList->CreateEmptyEditTable("EmailMessageId", true);
$eList->SourceTable = $objSession->GetEditTable("EmailMessage");
}
else {
$eList->SourceTable = $objSession->GetEditTable("EmailMessage");
}
$sql = "SELECT MIN(EmailMessageId) as MinId FROM ".$eList->SourceTable;
$as = $ado->Execute($sql);
if($as && !$as->EOF)
{
$MinId = (int)$as->fields["MinId"];
}
else {
$MinId = 0;
}
$MinId--;
while($rs && !$rs->EOF)
{
$data = $rs->fields;
$eList->AddEmailEvent($data["Template"], $data["MessageType"], $_POST["LanguageId"], $data["EventId"]);
$sql = "UPDATE ".$eList->SourceTable." SET EmailMessageId=$MinId WHERE EmailMessageId=0 LIMIT 1";
$ado->Execute($sql);
$MinId--;
$rs->MoveNext();
}
unset($eList);
}
break;
case "m_lang_delete":
if($ro_perm) break;
if (isset($_POST["itemlist"]))
{
$Phrases = new clsPhraseList();
$Messages = new clsEmailMessageList();
foreach($_POST["itemlist"] as $id)
{
$objLanguages->DeleteLanguage($id);
$Phrases->DeleteLanguage($id);
$Messages->DeleteLanguage($id);
}
unset($Phrases);
unset($Messages);
}
break;
case "m_lang_select":
if($ro_perm) break;
$LangId = (int)$_POST["langselect"];
if($LangId)
{
if($objSession->Get("PortalUserId")>0)
{
//echo "$LangId";
$objSession->SetPersistantVariable("Language",$LangId);
}
$objSession->Set("Language",$LangId);
$objSession->Update();
$m_var_list_update["lang"] = $LangId;
$m_var_list["lang"] = $LangId;
}
break;
case "m_phrase_edit":
$objSession->SetVariable("HasChanges", 1);
$objPhraseList = new clsPhraseList();
if((int)$_POST["direct"] != 1)
$objPhraseList->SourceTable = $objSession->GetEditTable("Phrase");
$Phrases = $_POST["name"];
foreach($Phrases as $PhraseId =>$name)
{
if($PhraseId>0)
{
$objPhraseList->EditPhrase($PhraseId,$_POST["name"][$PhraseId],$_POST["LanguageId"],$_POST["translation"][$PhraseId],$_POST["phrasetype"][$PhraseId]);
}
}
if(strlen($_POST["name"][0]) && strlen($_POST["translation"][0]) && $_POST['Action1'] == "new")
{
$r = $objPhraseList->AddPhrase($_POST["name"][0],$_POST["LanguageId"],$_POST["translation"][0],$_POST["phrasetype"][0]);
if ($r != "Error") {
$ado = &GetADODBConnection();
$rs = $ado->Execute("SELECT MIN(PhraseId) as MinValue FROM ".$objPhraseList->SourceTable);
$NewId = $rs->fields["MinValue"]-1;
$sql = "UPDATE ".$objPhraseList->SourceTable." SET PhraseId=".$NewId." WHERE PhraseId=$PhraseId";
if($objSession->HasSystemPermission("DEBUG.LIST"))
echo $sql."<br>\n";
$ado->Execute($sql);
}
else {
$add_error = "Language tag with the same name already exists!";
}
}
else if ($_POST['Action1'] == "new") {
$add_error = "Fields name and translation are required!";
}
unset($objPhraseList);
break;
case "m_config_missing_phrase":
if($ro_perm) break;
$LangId = $_POST["LangId"];
$ThemeId = $_POST["ThemeId"];
if(is_array($_POST["Phrase"]))
{
$objPhraseList = new clsPhraseList();
$objPhraseList->SourceTable = $objSession->GetSessionKey()."_".$ThemeId."_labels";
foreach($_POST["Phrase"] as $p => $value)
{
if(strlen($value))
{
$obj = $objPhraseList->GetItemByField("Phrase",$p,TRUE);
if(is_object($obj))
{
if($obj->Get("Phrase")==$p)
{
$obj->Set("Translation",$value);
$obj->Update();
}
else
$objPhraseList->AddPhrase($p,$LangId,$value,1);
}
else
$objPhraseList->AddPhrase($p,$LangId,$value,1);
}
}
}
break;
case "m_phrase_delete":
$objSession->SetVariable("HasChanges", 1);
if (isset($_POST["itemlist"]))
{
foreach($_POST["itemlist"] as $id)
{
$sql = "UPDATE ".$objSession->GetEditTable("Phrase")." SET LanguageId = 0 WHERE PhraseId = ".$id;
$ado = &GetADODBConnection();
$ado->Execute($sql);
}
}
unset($objPhraseList);
break;
case "m_emailevent_disable":
if($ro_perm) break;
$objEvents = new clsEventList();
if (isset($_POST["itemlist"]))
{
foreach($_POST["itemlist"] as $id)
{
$m =& $objEvents->GetItem($id);
$m->Set("Enabled",0);
$m->Update();
}
}
unset($objEvents);
break;
case "m_emailevent_enable":
if($ro_perm) break;
$objEvents = new clsEventList();
if (isset($_POST["itemlist"]))
{
foreach($_POST["itemlist"] as $id)
{
$m =& $objEvents->GetItem($id);
$m->Set("Enabled",1);
$m->Update();
}
}
unset($objEvents);
break;
case "m_emailevent_frontonly":
if($ro_perm) break;
$objEvents = new clsEventList();
if (isset($_POST["itemlist"]))
{
foreach($_POST["itemlist"] as $id)
{
$m =& $objEvents->GetItem($id);
$m->Set("Enabled",2);
$m->Update();
}
}
unset($objEvents);
break;
case "m_dlid":
echo $Action.":".$DownloadId;
die();
break;
case "m_emailevent_user":
if($ro_perm) break;
$objEvents = new clsEventList();
//phpinfo(INFO_VARIABLES);
//$objEvents->SourceTable = $objSession->GetEditTable("Events");
$ids = $_POST["EventId"];
$ids = str_replace("[","",$ids);
$ids = str_replace("]","",$ids);
$ids = str_replace("\"","",$ids);
$ids = str_replace("\\","",$ids);
$idlist = explode(",",$ids);
foreach($idlist as $EventId)
{
$id = (int)stripslashes($EventId);
$e =& $objEvents->GetItem((int)$EventId);
$e->Set("FromUserId", $_POST["FromUserId"]);
$e->Update();
}
$objEvents->Clear();
unset($objEvents);
break;
case "m_emailevent_edit":
$Template = $_POST["headers"];
if(strlen($Template))
{
$Template .= "\n";
}
$Template = str_replace("\n\n","",$Template);
$Template .= "Subject: "._unhtmlentities($_POST['subject'])."\n\n";
$Template .= $_POST["messageBody"];
$objMessages = new clsEmailMessageList();
$objMessages->SourceTable = $objSession->GetEditTable("EmailMessage");
$m =& $objMessages->GetItem($_POST["MessageId"]);
if(is_object($m))
{
if($_POST["sendhtml"]==1)
{
$m->Set("MessageType","html");
}
else
$m->Set("MessageType","text");
$m->Set("Template",$Template);
$m->Update();
}
break;
case "m_config_edit":
//phpinfo(INFO_VARIABLES);
if($ro_perm) break;
$objAdmin = new clsConfigAdmin();
$objAdmin->module = $_POST["module"];
$objAdmin->section = $_POST["section"];
if($objAdmin->section=="in-portal:configure_users")
{
if(strlen($_POST["RootPass"]) && strlen($_POST["RootPassVerify"]))
{
if($_POST["RootPass"]==$_POST["RootPassVerify"])
{
$_POST["RootPass"] = md5($_POST["RootPass"]);
}
}
else
{
$_POST["RootPass"] = $objConfig->Get("RootPass");
$_POST["RootPassVerify"] = $objConfig->Get("RootPassVerify");
}
}
$objAdmin->LoadItems(FALSE);
$objAdmin->SaveItems($_POST);
break;
case "m_mod_enable":
if($ro_perm) break;
if (isset($_POST["itemlist"]))
{
foreach($_POST["itemlist"] as $id)
{
$m =& $objModules->GetItemByField("Name",$id);
if(is_object($m))
{
$m->Set("Loaded",1);
$m->Update();
}
}
$_GET["Refresh"] = 1;
}
break;
case "m_mod_disable":
if($ro_perm) break;
if (isset($_POST["itemlist"]))
{
foreach($_POST["itemlist"] as $id)
{
if($id != "In-Portal")
{
$m =& $objModules->GetItemByField("Name",$id);
if(is_object($m))
{
$m->Set("Loaded",0);
$m->Update();
}
}
}
$_GET["Refresh"] = 1;
}
break;
case "m_img_add":
$objImageList = new clsImageList();
$objImageList->SourceTable = $objSession->GetEditTable("Images");
$LocalImage=0;
$LocalThumb=0;
$DestDir = "kernel/images/";
$UserThumbSource = (int)$_POST["imgLocalThumb"];
$LocalThumb = $UserThumbSource;
$thumb_url = !$LocalThumb? $_POST["imgThumbUrl"] : "";
if($_POST["imgSameImages"])
{
$LocalImage = $LocalThumb;
$full_url = $thumb_url;
}
else
{
$LocalImage = (int)$_POST["imgLocalFull"];
$file = $_FILES["imgFullFile"];
$full_url = $LocalImage? "" : $_POST["imgFullUrl"];
}
if((!strlen($thumb_url) && !$LocalThumb) || (!strlen($full_url) && !$LocalImage))
{
break;
}
$ado = &GetADODBConnection();
$NewId = $ado->GetOne('SELECT MIN(ImageId) as MinValue FROM '.$objImageList->SourceTable);
if($NewId > 0) $NewId = 0;
$NewId--;
$img = $objImageList->Add($_POST["imgName"], $_POST["imgAlt"], $_POST["ResourceId"], $LocalImage, $LocalThumb, $full_url, $thumb_url, (int)$_POST["imgEnabled"], 0, (int)$_POST["imgDefault"], 0,(int)$_POST["imgSameImages"], $NewId);
$img->Set("ImageId", $NewId);
// $img->debuglevel=1;
/*
$sql = "UPDATE ".$objImageList->SourceTable." SET ImageId=".$NewId." WHERE ImageId=0";
$ado->Execute($sql);
// $img->Update();
*/
// echo "SL: $sql $NewId<BR>";
// $img->debuglevel=1;
$img->Pending=TRUE;
if($LocalImage)
{
$file = $_FILES["imgFullFile"];
if(is_array($file))
{
if($file["size"]>0)
{
$img->Set("LocalPath",$img->StoreUploadedImage($file,1, $DestDir,0));
$uploaded=1;
}
}
}
if($LocalThumb)
{
$thumb = $_FILES["imgThumbFile"];
if(is_array($thumb))
{
if($thumb["size"]>0)
{
$img->Set("ThumbPath",$img->StoreUploadedImage($thumb,1, $DestDir,1));
$uploaded=1;
}
}
}
if($uploaded==1)
$img->Update();
break;
case "m_img_edit":
$objImageList = new clsImageList();
$objImageList->SourceTable = $objSession->GetEditTable("Images");
// $img->debuglevel=1;
$img = $objImageList->GetItem($_POST["ImageId"]);
## Get original values
$LocalImage = $img->Get("LocalImage");
$LocalThumb = $img->Get("LocalThumb");
$SameImages = $img->Get("SameImages");
$ThumbPath = $img->Get("ThumbPath");
## New values
$LocalThumbN = (int)$_POST["imgLocalThumb"];
$LocalImageN = (int)$_POST["imgLocalFull"];
$FULLFile = $_FILES["imgFullFile"];
$THFile = $_FILES["imgThumbFile"];
$DestDir = "kernel/images/";
$img->Pending = FALSE;
$SameImagesN = 0;
$uploaded = 0;
## Images were the same, but not any more
if ($SameImages && !$_POST["imgSameImages"])
{
## TH was a local file
if ($LocalThumb)
{
## TH image
{
## Try to Delete OLD FULL
$img->DeleteLocalImage(FALSE, TRUE);
## FULL image select, but field EMPTY - make a copy of old TH as FULL
if ($LocalImageN && !(int)$FULLFile["size"])
{
// echo $pathToPending = $img->GetImageDir();
if (!eregi("pending/$", $pathToPending))
$pathToPending.= "pending/";
$LocalThumb_File = $img->GetFileName(1);
// echo "<b>CAN'T FIND FILE:</b> ".$pathToPending.$LocalThumb_File."<BR>";
if (file_exists($pathToPending.$LocalThumb_File))
{
$LocalThumb_FileN = eregi_replace("^th_", "", $LocalThumb_File);
$LocalThumb_FullFileN = $pathToPending.$LocalThumb_FileN;
@unlink($LocalThumb_FullFileN);
@copy($pathToPending.$LocalThumb_File, $LocalThumb_FullFileN);
$uploaded = 1;
$copied = 1;
// echo "COPING: ".$DestDir."pending/".$LocalThumb_FileN." <BR>";
}
else
{
// echo "CAN'T FIND FILE: ".$pathToPending.$LocalThumb_File."<BR>";
}
}
## Upload new FULL image
elseif ($LocalImageN && (int)$FULLFile['size'])
{
$FULL_FileToUpload = $FULLFile;
$FULL_URL = "";
// echo " Upload new FULL image";
}
## Full is URL
elseif (!$LocalImageN)
{
$img->DeleteLocalImage(FALSE, TRUE);
$FULL_URL = $_POST['imgFullUrl'];
$FULL_FileToUpload = "";
}
else
{
// echo " ## Unknow condition";
}
## Take care of Thumbnail here
if ($LocalThumbN)
{
## Delete old if NEW TH image selected
if ((int)$THFile['size'])
{
$img->DeleteLocalImage(TRUE, FALSE);
$TH_FileToUpload = $THFile;
}
else
$TH_FileToUpload = "";
}
else
{
$img->DeleteLocalImage(TRUE, FALSE);
$TH_FileToUpload = "";
$TH_URL = $_POST['imgThumbUrl'];
}
}
}
## TH was URL
else
{
## Take care of FULL image here
if ($LocalImageN && (int)$FULLFile["size"])
{
$FULL_FileToUpload = $FULLFile;
$FULL_URL = "";
}
## Full is URL (or image size 0)
else
{
$FULL_FileToUpload = "";
$FULL_URL = $_POST['imgFullUrl'];
}
## Take care of Thumbnail here
if ($LocalThumbN)
{
$TH_FileToUpload = (int)$THFile['size']? $THFile : "";
$TH_URL = "";
}
else
{
$TH_FileToUpload = "";
$TH_URL = $_POST['imgThumbUrl'];
}
}
}
## Images were the same, and still the same
elseif ($SameImages && $_POST['imgSameImages'])
{
## Take care of Thumbnail & FULL here
if ($LocalThumbN)
{
if ((int)$THFile['size'])
{
$img->DeleteLocalImage(TRUE, FALSE);
$TH_FileToUpload = $THFile;
}
else
$TH_FileToUpload = "";
$FULL_URL = $TH_URL = "";
}
else
{
$TH_FileToUpload = $FULL_FileToUpload = "";
$FULL_URL = $TH_URL = $_POST['imgThumbUrl'];
}
## Delete old FULL image
$img->DeleteLocalImage(FALSE,TRUE);
$SameImagesN = 1;
}
## Images were NOT the same, and selected as the same now
elseif (!$SameImages && $_POST["imgSameImages"])
{
## Take care of Thumbnail & FULL here
if ($LocalThumbN)
{
if ((int)$THFile['size'])
{
$img->DeleteLocalImage(TRUE, FALSE);
$TH_FileToUpload = $THFile;
}
else
$TH_FileToUpload = "";
$FULL_URL = $TH_URL = "";
}
else
{
$img->DeleteLocalImage(TRUE, FALSE);
$TH_FileToUpload = $FULL_FileToUpload = "";
$FULL_URL = $TH_URL = $_POST['imgThumbUrl'];
}
## Clean up FULL image
$img->DeleteLocalImage(FALSE, TRUE);
$SameImagesN = 1;
}
## Images were NOT the same, and selected as NOT the same
elseif (!$SameImages && !$_POST["imgSameImages"])
{
## Take care of Thumbnail
if ($LocalThumbN)
{
if ((int)$THFile['size'])
{
$img->DeleteLocalImage(TRUE, FALSE);
$TH_FileToUpload = $THFile;
}
else
$TH_FileToUpload = "";
$TH_URL = "";
}
else
{
$img->DeleteLocalImage(TRUE, FALSE);
$TH_FileToUpload = "";
$TH_URL = $_POST['imgThumbUrl'];
}
## Take care of FULL here
if ($LocalImageN)
{
if ((int)$FULLFile['size'])
{
$img->DeleteLocalImage(FALSE, TRUE);
$FULL_FileToUpload = $FULLFile;
}
else
$FULL_FileToUpload = "";
$FULL_URL = "";
}
else
{
$img->DeleteLocalImage(FALSE, TRUE);
$FULL_FileToUpload = "";
$FULL_URL = $_POST['imgFullUrl'];
}
}
## Unknow condition
else
{
;
}
$img = $objImageList->Edit($_POST["ImageId"],$_POST["imgName"], $_POST["imgAlt"], $_POST["ResourceId"], $LocalImageN, $LocalThumbN, $FULL_URL, $TH_URL, (int)$_POST["imgEnabled"], (int)$_POST["imgPriority"], (int)$_POST["imgDefault"], 0, $SameImagesN);
// echo "<B>DATA:</B> <BR> LocalImageN: $LocalImageN, LocalThumbN: $LocalThumbN, FULL_URL: $FULL_URL, TH_URL: $TH_URL, SameImagesN: $SameImagesN <BR>";
$img->Pending = TRUE;
if (!empty($FULL_FileToUpload))
{
$img->Set("LocalPath",$img->StoreUploadedImage($FULL_FileToUpload, 1, $DestDir, 0));
$uploaded = 1;
}
/*
elseif (!$LocalImageN)
{
$img->Set("LocalPath", "");
$uploaded = 1;
}
*/
if (!empty($TH_FileToUpload))
{
$img->Set("ThumbPath", $img->StoreUploadedImage($TH_FileToUpload, 1, $DestDir, 1));
$uploaded = 1;
}
if ($copied)
{
$img->Set("LocalPath", $DestDir."pending/".$LocalThumb_FileN);
$uploaded = 1;
}
if($uploaded==1)
$img->Update();
break;
case "m_img_move_up":
if (isset($_POST["itemlist"]))
{
$objImageList = new clsImageList();
$objImageList->SourceTable = $objSession->GetEditTable("Images");
foreach($_POST["itemlist"] as $id)
{
$img = $objImageList->GetItem($id);
$img->MoveUp();
}
}
break;
case "m_img_move_down":
if (isset($_POST["itemlist"]))
{
$objImageList = new clsImageList();
$objImageList->SourceTable = $objSession->GetEditTable("Images");
$itemlist=array_reverse($_POST["itemlist"]);
foreach($itemlist as $id)
{
$img = $objImageList->GetItem($id);
$img->MoveDown();
}
}
break;
case "m_img_delete":
if(isset($_POST["itemlist"]))
{
$objImageList = new clsImageList();
$objImageList->SourceTable = $objSession->GetEditTable("Images");
foreach($_POST["itemlist"] as $id)
{
- $img = $objImageList->GetItem($id);
+ $img = $objImageList->GetItem($id);
$img->Set("ResourceId", 0);
$img->Update();
//$img->Delete();
}
}
break;
case "m_restore_delete":
if($ro_perm) break;
$bdate = $_POST["backupdate"];
if($bdate>0)
{
$BackupFile = $objConfig->Get("Backup_Path")."/dump".$bdate.".txt";
if(file_exists($BackupFile))
unlink($BackupFile);
}
break;
case "m_taglib":
include($pathtoroot."kernel/include/tag-class.php");
ParseTagLibrary();
break;
case "m_sql_query":
if($ro_perm) break;
$SqlQuery = $_POST["sql"];
$ado = &GetADODBConnection();
if(strlen($sql))
{
$SqlResult = $ado->Execute(stripslashes($SqlQuery));
$SqlError = $ado->ErrorMsg();
$SqlErrorNum = $ado->ErrorNo();
}
break;
case "m_purge_email_log":
if($ro_perm) break;
$ado = &GetADODBConnection();
$sql = "DELETE FROM ".GetTablePrefix()."EmailLog";
$ado->Execute($sql);
break;
case "m_session_delete":
if($ro_perm) break;
$ado = &GetADODBConnection();
if (count($_POST['itemlist']) > 0) {
foreach($_POST["itemlist"] as $id)
{
$sql = "DELETE FROM ".GetTablePrefix()."UserSession WHERE SessionKey='$id'";
$ado->Execute($sql);
}
}
else {
$sql = "DELETE FROM ".GetTablePrefix()."UserSession WHERE Status='0'";
$ado->Execute($sql);
}
break;
case "m_add_rule":
$objEditItems = new clsBanRuleList();
$objEditItems->SourceTable = $objSession->GetEditTable("BanRules");
//$ItemType,$RuleType,$ItemField,$ItemVerb,$ItemValue,$Priority,$Status;
$objEditItems->AddRule($_POST["rule_itemtype"],$_POST["rule_type"],$_POST["rule_field"],
$_POST["rule_verb"],$_POST["rule_value"],(int)$_POST["rule_priority"],
(int)$_POST["rule_status"], $_POST['rule_error']);
break;
case "m_edit_rule":
$objEditItems = new clsBanRuleList();
$objEditItems->SourceTable = $objSession->GetEditTable("BanRules");
//$ItemType,$RuleType,$ItemField,$ItemVerb,$ItemValue,$Priority,$Status;
$objEditItems->EditRule($_POST["rule_id"],$_POST["rule_itemtype"],$_POST["rule_type"],$_POST["rule_field"],
$_POST["rule_verb"],$_POST["rule_value"],(int)$_POST["rule_priority"],
(int)$_POST["rule_status"], $_POST['rule_error']);
break;
case "m_rule_move_up":
if($ro_perm) break;
if(isset($_POST["itemlist"]))
{
foreach($_POST["itemlist"] as $id)
{
$i = $objBanList->GetItem($id);
$i->Increment("Priority");
}
}
break;
case "m_rule_move_down":
if($ro_perm) break;
if(isset($_POST["itemlist"]))
{
foreach($_POST["itemlist"] as $id)
{
$i = $objBanList->GetItem($id);
$i->Decrement("Priority");
}
}
break;
case "m_rule_delete":
if($ro_perm) break;
if(isset($_POST["itemlist"]))
{
foreach($_POST["itemlist"] as $id)
{
$i = $objBanList->GetItem($id);
$i->Delete();
}
}
break;
case "m_ban_user":
if($ro_perm) break;
if($_POST["UserEditStatus"]==1)
{
$UserId = $_POST["user_id"];
$u = $objUsers->GetItem($UserId);
if(is_object($u))
{
if((int)$_POST["ban_login"])
{
if(strlen($_POST["user_login"]))
$objBanList->AddRule(6,0,"Login",3,$_POST["user_login"],0,1);
}
if((int)$_POST["ban_email"])
{
if(strlen($_POST["user_email"]))
$objBanList->AddRule(6,0,"Email",3,$_POST["user_email"],0,1);
}
if((int)$_POST["ban_ip"])
{
if(strlen($_POST["user_ip"]))
$objBanList->AddRule(6,0,"ip",3,$_POST["user_ip"],0,1);
}
$u->Deny();
}
}
break;
}
/* image upload management */
if( isset($_POST['img']) && $_POST['img'] == 1 )
{
foreach($_FILES as $img => $FILE)
{
$name = $_POST["img_Name_$img"];
$alt = $_POST["img_Alt_$img"];
$url = $_POST["img_Url_$img"];
$res_id = $_POST["img_Res_$img"];
$relvalue = $_POST["img_Rel_$img"];
$thumb = (int)$_POST["img_Thumb_$img"];
$dest = AddSlash($_POST["img_DestDir_$img"]);
if($_POST["img_Del_$img"]=="Delete")
{
$img = $objImageList->GetImageByResource($res_id,$relvalue);
$img->Delete();
unset($img);
$objImageList->Clear();
}
else
{
if($FILE["size"]>0)
{
/* an image was uploaded */
$objImageList->HandleImageUpload($FILE,$res_id,$relvalue,$dest, $name,$alt,$thumb);
}
else
{ /* remote images handled here */
if(strlen($url)>0)
{
if($relvalue>0)
{
$img = $objImageList->GetImageByResource($res_id,$relvalue);
$img->Set("Name",$name);
$img->Set("AltName", $alt);
$img->Set("IsThumbnail",$thumb);
$img->Set("Url",$url);
$img->Update();
}
else
{
$relvalue = $objImageList->GetNextRelateValue($res_id);
$objImageList->NewRemoteImage($url,$res_id,$relvalue, $name, $alt, $thumb);
}
}
}
}
}
}
// ALL Saving Stuff From Temp Tables Heppens Here
//echo "==== BEGIN ==== <br>";
$has_perm = $objSession->HasSystemPermission("SYSTEM_ACCESS.READONLY");
//echo "PortalUserID: [".$objSession->Get("PortalUserId")."]<br>";
//print_pre($objSession);
//echo "PermSet: [".$has_perm."]<br>";
if( !$has_perm )
{
/* category Edit */
if( GetVar('CatEditStatus') == 1 )
{
$adodbConnection = &GetADODBConnection();
// $sql = "SELECT * FROM ".$objSession->GetEditTable("Category")." WHERE CategoryId=0";
$sql = "SELECT ParentId FROM ".$objSession->GetEditTable("Category")." WHERE CategoryId=-1";
$rs = $adodbConnection->Execute($sql);
while ($rs && !$rs->EOF)
{
if($rs->fields["ParentId"] > 0) RunUp($rs->fields["ParentId"],"Increment_Count");
$rs->MoveNext();
}
$objCatList->CopyFromEditTable("CategoryId");
$objCustomDataList->CopyFromEditTable("CustomDataId");
$objCatList->Clear();
if($_REQUEST['CategoryId'] > 0) // not root category is updated
{
$objImages = new clsImageList();
$objImages->CopyFromEditTable("ImageId");
}
}
if( GetVar('CatEditStatus') == 2 )
{
$objCatList->PurgeEditTable("CategoryId");
$objCustomDataList->PurgeEditTable("CustomDataId");
if($_REQUEST['CategoryId'] > 0) // not root category is updated
{
$objImages = new clsImageList();
- $objImages->CopyFromEditTable("ImageId");
- //$objImages->PurgeEditTable("ImageId");
+ //$objImages->CopyFromEditTable("ImageId");
+ $objImages->PurgeEditTable("ImageId");
}
$objCatList->Clear();
}
/* User Edit */
if( GetVar('UserEditStatus') == 1 )
{
$objUserGroupsList = new clsUserGroupList();
$objUserGroupsList->CopyFromEditTable("PortalUserId");
$objUsers->CopyFromEditTable("PortalUserId");
$objCustomDataList->CopyFromEditTable("CustomDataId");
$objGroups->Clear();
$objImages = new clsImageList();
$objImages->CopyFromEditTable("ImageId");
}
if( GetVar('UserEditStatus') == 2 )
{
$objUserGroupsList = new clsUserGroupList();
$objGroups->PurgeEditTable("PortalUserId");
$objUserGroupsList->PurgeEditTable("PortalUserId");
$objCustomDataList->PurgeEditTable("CustomDataId");
$objGroups->Clear();
}
/* Group Edit */
if( GetVar('GroupEditStatus') == 1 )
{
$objUserGroupsList = new clsUserGroupList();
$objUserGroupsList->CopyFromEditTable("GroupId");
$objGroups->CopyFromEditTable("GroupId");
$objCustomDataList->CopyFromEditTable("CustomDataId");
$objGroups->Clear();
}
if( GetVar('GroupEditStatus') == 2 )
{
$objUserGroupsList = new clsUserGroupList();
$objGroups->PurgeEditTable("GroupId");
$objCustomDataList->PurgeEditTable("CustomDataId");
$objUserGroupsList->PurgeEditTable("PortalUserId");
$objGroups->Clear();
}
/* Theme Edit */
if( GetVar('ThemeEditStatus') == 1 )
{
$objThemes->CopyFromEditTable();
$objThemes->Clear();
}
if( GetVar('ThemeEditStatus') == 2 )
{
$objThemes->PurgeEditTable();
$objThemes->Clear();
}
/* Language Edit */
if( GetVar('LangEditStatus') == 1 )
{
$objLanguages->CopyFromEditTable();
$objLanguages->Clear();
$objLanguages->PurgeEditTable();
$Phrases = new clsPhraseList();
$Phrases->CopyFromEditTable();
$Phrases->Clear();
$Phrases->PurgeEditTable();
$Messages = new clsEmailMessageList();
$Messages->CopyFromEditTable();
$Messages->Clear();
}
if( GetVar('LangEditStatus') == 2 )
{
$objLanguages->PurgeEditTable();
$objLanguages->Clear();
$Phrases = new clsPhraseList();
$Phrases->PurgeEditTable();
$Messages = new clsEmailMessageList();
$Messages->PurgeEditTable();
}
if( GetVar('MissingLangEditStatus') == 1 )
{
$objPhraseList = new clsPhraseList();
$objPhraseList->SourceTable = $objSession->GetSessionKey()."_".$ThemeId."_labels";
$objEditList = new clsPhraseList();
$objEditList->SourceTable = $objSession->GetEditTable("Phrase");
$ado = &GetADODBConnection();
$rs = $ado->Execute("SELECT MIN(PhraseId) as MinValue FROM ".$objEditList->SourceTable);
$NewId = $rs->fields["MinValue"]-1;
$objPhraseList->Query_Item("SELECT * FROM ".$objPhraseList->SourceTable);
foreach($objPhraseList->Items as $p)
{
if(strlen($p->Get("Translation"))>0)
{
$p->tablename = $objEditList->SourceTable;
$p->Dirty();
$p->UnsetIDField();
$p->Set("PhraseId",$NewId);
$NewId--;
$p->Create();
}
}
$ado->Execute("DROP TABLE IF EXISTS ".$objPhraseList->SourceTable);
}
if( GetVar('MissingLangEditStatus') == 2 )
{
$table = $objSession->GetSessionKey()."_".$ThemeId."_labels";
$ado = &GetADODBConnection();
$ado->Execute("DROP TABLE IF EXISTS ".$table);
}
/* Ban Rule Edit */
if( GetVar('RuleEditStatus') == 1 )
{
$objBanList->CopyFromEditTable("RuleId");
$objBanList->Clear();
}
if( GetVar('RuleEditStatus') == 2 )
{
$objBanList->PurgeEditTable("RuleId");
$objBanList->Clear();
}
}
elseif( defined('DEBUG_ACTIONS') )
{
if( isset($_REQUEST['Action']) && $_REQUEST['Action'] )
echo "<b>USER HAS RO-ACCESS</b> on action [<b>".$_REQUEST['Action']."</b>]<br>";
}
//echo "==== END ==== <br>";
?>
\ No newline at end of file
Property changes on: trunk/kernel/action.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.62
\ No newline at end of property
+1.63
\ No newline at end of property
Index: trunk/kernel/include/itemdb.php
===================================================================
--- trunk/kernel/include/itemdb.php (revision 899)
+++ trunk/kernel/include/itemdb.php (revision 900)
@@ -1,611 +1,611 @@
<?php
define('FT_OPTION', 1); // option formatter
class clsItemDB
{
var $Formatters = Array(); // by Alex
var $m_dirtyFieldsMap = array();
var $Data = array();
var $adodbConnection;
var $tablename;
var $BasePermission;
var $id_field;
var $NoResourceId;
var $debuglevel;
var $SelectSQL = 'SELECT * FROM %s WHERE %s';
function clsItemDB()
{
$this->adodbConnection = &GetADODBConnection();
$this->tablename="";
$this->NoResourceId=0;
$this->debuglevel=0;
}
// ============================================================================================
function GetFormatter($field)
{
return $this->HasFormatter($field) ? $this->Formatters[$field] : false;
}
function SetFormatter($field, $type, $params)
{
// by Alex
// all params after 2nd are formmater type specific
$this->Formatters[$field]['type'] = $type;
switch($type)
{
case FT_OPTION:
$this->Formatters[$field]['options'] = $params;
break;
}
}
/*
function FormatFields()
{
// format item in list data before printing
foreach($this->Formatters as $field => $formatter)
$this->Data[$field] = $this->FormatField($field);
}
*/
function FormatField($field)
{
// formats single field if it has formatter
if( $this->HasFormatter($field) )
{
$fmt = $this->Formatters[$field];
switch($fmt['type'])
{
case FT_OPTION:
return $fmt['options'][ $this->Data[$field] ];
break;
}
}
else
return $this->Get($field);
}
function HasFormatter($field)
{
// checks if formatter is set for field
return isset($this->Formatters[$field]) ? 1 : 0;
}
// ============================================================================================
function UnsetIdField()
{
$f = $this->IdField();
unset($this->Data[$f]);
unset($this->m_dirtyFieldsMap[$f]);
}
function UnsetField($field)
{
unset($this->Data[$field]);
unset($this->m_dirtyFieldsMap[$field]);
}
function IdField()
{
if(!strlen($this->id_field))
{
return $this->tablename."Id";
}
else
return $this->id_field;
}
function UniqueId()
{
return $this->Get($this->IdField());
}
function SetUniqueId($value)
{
$var = $this->IdField();
$this->Set($var, $value);
}
function SetModified($UserId=NULL,$modificationDate=null)
{
global $objSession;
$keys = array_keys($this->Data);
if(in_array("Modified",$keys))
{
$this->Set("Modified", isset($modificationDate) ? $modificationDate : adodb_date("U") );
}
if(in_array("ModifiedById",$keys))
{
if(!$UserId)
$UserId = $objSession->Get("PortalUserId");
$this->Set("ModifiedById",$UserId);
}
}
function PrintVars()
{
echo '<pre>'.print_r($this->Data, true).'</pre>';
}
// =================================================================
function GetFormatted($name)
{
// get formatted field value
return $this->FormatField($name);
}
function Get($name)
{
// get un-formatted field value
//if( !isset($this->Data[$name]) ) print_pre( debug_backtrace() );
return $this->HasField($name) ? $this->Data[$name] : '';
}
// =================================================================
function HasField($name)
{
// checks if field exists in item
return isset($this->Data[$name]) ? 1 : 0;
}
/**
* Set's value(-s) of field(-s) specified.
* Modifies HasChanges flag automatically.
*
* @param string/array $name
* @param string/array $value
* @access public
*/
function Set($name, $value)
{
//echo "Setting Field <b>$name</b>: = [$value]<br>";
if( is_array($name) )
{
for ($i=0; $i < sizeof($name); $i++)
{
$this->_Set($name[$i],$value[$i]);
}
}
else
{
$this->_Set($name,$value);
}
}
/**
* Set's value(-s) of field(-s) specified.
* Modifies HasChanges flag automatically.
*
* @param string $name
* @param string $value
* @access private
*/
function _Set($name,$value)
{
$var = 'm_'.$name;
if( !$this->HasField($name) || $this->Data[$name] != $value )
{
if( !(isset($_GET['new']) && $_GET['new']) ) {
$this->DetectChanges($name, $value);
}
$this->Data[$name] = $value;
$this->m_dirtyFieldsMap[$name] = $value;
}
}
function Dirty($list=NULL)
{
if($list==NULL)
{
foreach($this->Data as $field => $value)
{
$this->m_dirtyFieldsMap[$field] = $value;
}
}
else
{
foreach($list as $field)
{
$this->m_dirtyFieldsMap[$field] = $this->Data[$field];
}
}
}
function Clean($list=NULL)
{
if($list == NULL)
{
unset($this->m_dirtyFieldsMap);
$this->m_dirtyFieldsMap=array();
}
else
{
foreach($list as $value)
{
$varname = "m_" . $value;
unset($this->m_dirtyFieldsMap[$value]);
}
}
}
function SetDebugLevel($value)
{
$this->debuglevel = $value;
}
function SetFromArray($data, $dirty = false)
{
if(is_array($data))
{
$this->Data = $data;
if($dirty) $this->m_dirtyFieldsMap = $data;
}
}
function GetData()
{
return $this->Data;
}
function SetData($data, $dirty = false)
{
$this->SetFromArray($data, $dirty);
}
function Delete()
{
global $Errors;
if($this->Get($this->IdField())==0)
{
$Errors->AddError("error.AppError",NULL,'Internal error: Delete requires set id',"",get_class($this),"Delete");
return false;
}
$sql = sprintf('DELETE FROM %s WHERE %s = %s', $this->tablename, $this->IdField(),
$this->UniqueId());
if($this->debuglevel>0)
echo $sql."<br>";
if ($this->adodbConnection->Execute($sql) === false)
{
$Errors->AddError("error.DatabaseError",NULL,$this->adodbConnection->ErrorMsg(),"",get_class($this),"Delete");
return false;
}
return true;
}
function Update($UpdatedBy=NULL,$modificationDate = null)
{
global $Errors, $objSession;
if(count($this->m_dirtyFieldsMap) == 0)
return true;
$this->SetModified($UpdatedBy,$modificationDate);
$sql = "UPDATE ".$this->tablename ." SET ";
$first = 1;
-
+
foreach ($this->m_dirtyFieldsMap as $key => $value)
{
if(!is_numeric($key) && $key != $this->IdField() && $key!='ResourceId')
{
if($first)
{
if(isset($GLOBALS['_CopyFromEditTable']))
$sql = sprintf("%s %s=%s",$sql,$key,$this->adodbConnection->qstr(($value)));
else
$sql = sprintf("%s %s=%s",$sql,$key,$this->adodbConnection->qstr(stripslashes($value)));
$first = 0;
}
else
{
if(isset($GLOBALS['_CopyFromEditTable']))
$sql = sprintf("%s, %s=%s",$sql,$key,$this->adodbConnection->qstr(($value)));
else
$sql = sprintf("%s, %s=%s",$sql,$key,$this->adodbConnection->qstr(stripslashes($value)));
}
}
}
$sql = sprintf("%s WHERE %s = '%s'",$sql, $this->IdField(), $this->UniqueId());
if($this->debuglevel>0)
echo $sql."<br>";
if ($this->adodbConnection->Execute($sql) === false)
{
$Errors->AddError("error.DatabaseError",NULL,$this->adodbConnection->ErrorMsg(),"",get_class($this),"Update");
return false;
}
if ($objSession->GetVariable("HasChanges") == 2) {
$objSession->SetVariable("HasChanges", 1);
}
/* if ($this->adodbConnection->Affected_Rows() > 0) {
$objSession->SetVariable("HasChanges", 1);
}*/
return true;
}
function ReplaceID($new_id)
{
// replace item's id, because Update method
// is too dummy to do this autommatically
// USED in temporary table editing stuff
$db =& $this->adodbConnection;
$sql = "UPDATE %1\$s SET `%2\$s` = %3\$s WHERE `%2\$s` = %4\$s";
$sql = sprintf($sql, $this->tablename, $this->IdField(), $new_id, (int)$this->UniqueId() );
if($this->debuglevel > 0) echo $sql.'<br>';
$db->Execute($sql);
}
function CreateSQL()
{
global $Errors;
$sql = "INSERT IGNORE INTO ".$this->tablename." (";
$first = 1;
foreach ($this->Data as $key => $value)
{
if($first)
{
$sql = sprintf("%s %s",$sql,$key);
$first = 0;
}
else
{
$sql = sprintf("%s, %s",$sql,$key);
}
}
$sql = sprintf('%s ) VALUES (',$sql);
$first = 1;
foreach ($this->Data as $key => $value)
{
if( is_array($value) )
{
global $debugger;
$debugger->dumpVars($value);
$debugger->appendTrace();
trigger_error('Value of array type not allowed in method <b>CreateSQL</b> of <b>clsItemDB</b> class', E_USER_ERROR);
}
if($first)
{
if(isset($GLOBALS['_CopyFromEditTable']))
$sql = sprintf("%s %s",$sql,$this->adodbConnection->qstr(($value)));
else
$sql = sprintf("%s %s",$sql,$this->adodbConnection->qstr(stripslashes($value)));
$first = 0;
}
else
{
if(isset($GLOBALS['_CopyFromEditTable']))
$sql = sprintf("%s, %s",$sql,$this->adodbConnection->qstr(($value)));
else
$sql = sprintf("%s, %s",$sql,$this->adodbConnection->qstr(stripslashes($value)));
}
}
$sql = sprintf('%s)',$sql);
return $sql;
}
/**
* Set's HasChanges flag based on new field
* with $name with value $value.
*
* @param string $name
* @param string $value
* @access private
*/
function DetectChanges($name, $value)
{
global $objSession;
//echo "<b>class: ".get_class($this)."</b><br>";
if ($this->Data[$name] != $value && $value != '') {
//echo "$name Modified tt ".$this->Data[$name]." tt $value<br>";
if ($objSession->GetVariable("HasChanges") != 1) {
$objSession->SetVariable("HasChanges", 2);
}
}
}
function Create()
{
global $Errors, $objSession;
if($this->debuglevel) echo "Creating Item: ".get_class($this)."<br>";
if($this->NoResourceId!=1 && (int)$this->Get("ResourceId")==0)
{
$this->Set("ResourceId", GetNextResourceId());
}
$sql = $this->CreateSql();
if($this->debuglevel>0)
echo $sql."<br>\n";
if ($this->adodbConnection->Execute($sql) === false)
{
$Errors->AddError("error.DatabaseError",NULL,$this->adodbConnection->ErrorMsg(),"",get_class($this),"Create");
return false;
}
$this->SetUniqueId($this->adodbConnection->Insert_ID());
if ($objSession->GetVariable("HasChanges") == 2) {
$objSession->SetVariable("HasChanges", 1);
}
/*if ($this->adodbConnection->Affected_Rows() > 0) {
$objSession->SetVariable("HasChanges", 1);
} */
return true;
}
function Increment($field)
{
global $Errors;
$sql = "Update ".$this->tablename." set $field=$field+1 where ".$this->IdField()."=" . $this->UniqueId();
if($this->debuglevel>0)
echo $sql."<br>";
$result = $this->adodbConnection->Execute($sql);
if ($result === false)
{
$Errors->AddError("error.DatabaseError",NULL,$this->adodbConnection->ErrorMsg(),"",get_class($this),"Increment");
return false;
}
$this->Set($field,$this->Get($field)+1);
}
function Decrement($field)
{
global $Errors;
$sql = "Update ".$this->tablename." set $field=$field-1 where ".$this->IdField()."=" . $this->UniqueId();
if($this->debuglevel>0)
echo $sql;
$result = $this->adodbConnection->Execute($sql);
if ($result === false)
{
$Errors->AddError("error.DatabaseError",NULL,$this->adodbConnection->ErrorMsg(),"",get_class($this),"Decrement");
return false;
}
$this->Set($field,$this->Get($field)-1);
}
function GetFieldList($UseLoadedData=FALSE)
{
if(count($this->Data) && $UseLoadedData==TRUE)
{
$res = array_keys($this->Data);
}
else
{
$res = $this->adodbConnection->MetaColumnNames($this->tablename);
}
return $res;
}
function UsingTempTable()
{
global $objSession;
$temp = $objSession->GetEditTable($this->tablename);
$p = GetTablePrefix()."ses";
$t = substr($temp,0,strlen($p));
$ThisTable = substr($this->tablename,0,strlen($p));
if($t==$ThisTable)
{
return TRUE;
}
else
return FALSE;
}
function LoadFromDatabase($Id, $IdField = null) // custom IdField by Alex
{
global $objSession,$Errors;
if(!isset($Id))
{
$Errors->AddError("error.AppError",NULL,'Internal error: LoadFromDatabase id',"",get_class($this),"LoadFromDatabase");
return false;
}
// --------- multiple ids allowed: begin -----------------
$id_field = isset($IdField) ? $IdField : $this->IdField();
if( !is_array($id_field) ) $id_field = Array($id_field);
if( !is_array($Id) ) $Id = Array($Id);
$i = 0; $id_count = count($id_field);
$conditions = Array();
while($i < $id_count)
{
$conditions[] = "(`".$id_field[$i]."` = '".$Id[$i]."')";
$i++;
}
$sql = sprintf($this->SelectSQL, $this->tablename, implode(' AND ', $conditions) );
// --------- multiple ids allowed: end --------------------
if($this->debuglevel) echo "Load SQL: $sql<br>";
$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($this->debuglevel) print_pre($data);
if(is_array($data))
$this->SetFromArray($data);
$this->Clean();
return TRUE;
}
function FieldExists($field)
{
$res = array_key_exists($field,$this->Data);
return $res;
}
function ValueExists($Field,$Value)
{
$sql = "SELECT $Field FROM ".$this->tablename." WHERE $Field='$Value'";
$rs = $this->adodbConnection->Execute($sql);
if($rs && !$rs->EOF)
{
return TRUE;
}
else
return FALSE;
}
function FieldMax($Field)
{
$sql = "SELECT Max($Field) as m FROM ".$this->tablename;
$rs = $this->adodbConnection->Execute($sql);
if($rs && !$rs->EOF)
{
$ret = $rs->fields["m"];
}
else
$ret = 0;
}
function FieldMin($Field)
{
$sql = "SELECT Min($Field) as m FROM ".$this->tablename;
$rs = $this->adodbConnection->Execute($sql);
if($rs && !$rs->EOF)
{
$ret = $rs->fields["m"];
}
else
$ret = 0;
}
function TableExists($table = null)
{
// checks if table specified in item exists in db
$db =& $this->adodbConnection;
$sql = "SHOW TABLES LIKE '%s'";
if($table == null) $table = $this->tablename;
$rs = $db->Execute( sprintf($sql, $table) );
if( $rs->RecordCount() == 1 ) // table exists in normal case
return 1;
else // check if table exists in lowercase
$rs = $db->Execute( sprintf($sql, strtolower($table) ) );
return ($rs->RecordCount() == 1) ? 1 : 0;
}
}
?>
Property changes on: trunk/kernel/include/itemdb.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.22
\ No newline at end of property
+1.23
\ No newline at end of property
Index: trunk/kernel/include/image.php
===================================================================
--- trunk/kernel/include/image.php (revision 899)
+++ trunk/kernel/include/image.php (revision 900)
@@ -1,1153 +1,1207 @@
<?php
class clsImage extends clsParsedItem
{
var $Pending;
-
+
function clsImage($id=NULL)
- {
- global $objSession;
+ {
+ global $objSession;
+
+ $this->clsParsedItem();
+ $this->tablename = GetTablePrefix()."Images";
+ $this->Pending = FALSE;
+ $this->id_field = "ImageId";
+ $this->type=-30;
+ $this->TagPrefix = "image";
+ $this->NoResourceId=1;
+ if($id)
+ $this->LoadFromDatabase($id);
+ //$this->SetDebugLevel(0);
+ }
- $this->clsParsedItem();
- $this->tablename = GetTablePrefix()."Images";
- $this->Pending = FALSE;
- $this->id_field = "ImageId";
- $this->type=-30;
- $this->TagPrefix = "image";
- $this->NoResourceId=1;
- if($id)
- $this->LoadFromDatabase($id);
- //$this->SetDebugLevel(0);
- }
-
- function DetectChanges($name, $value)
- {
- global $objSession;
- //print_pre($_POST);
-
- if ($this->Data[$name] != $value) {
- //echo "$name Modified tt ".$this->Data[$name]." tt $value<br>";
- if (!stristr($name, 'Resource') && !stristr($name, 'ImageId')) {
- if ($objSession->GetVariable("HasChanges") != 1) {
- $objSession->SetVariable("HasChanges", 2);
+ function DetectChanges($name, $value)
+ {
+ global $objSession;
+ //print_pre($_POST);
+
+ if ($this->Data[$name] != $value) {
+ //echo "$name Modified tt ".$this->Data[$name]." tt $value<br>";
+ if (!stristr($name, 'Resource') && !stristr($name, 'ImageId')) {
+ if ($objSession->GetVariable("HasChanges") != 1) {
+ $objSession->SetVariable("HasChanges", 2);
+ }
}
}
}
- }
-
+
function GetFileName($thumb = 0)
{
global $pathtoroot;
if($thumb)
{
$p = $this->Get("ThumbPath");
}
else
{
- $p = $this->Get("LocalPath");
- if(!strlen($p) && $this->Get("SameImages"))
- {
- $p = $this->Get("ThumbPath");
- }
+ $p = $this->Get("LocalPath");
+ if(!strlen($p) && $this->Get("SameImages"))
+ {
+ $p = $this->Get("ThumbPath");
+ }
}
-
+
if(strlen($p))
{
$parts = pathinfo($pathtoroot.$p);
$filename = $parts["basename"];
}
else
- $filename = "";
-
+ $filename = "";
+
return $filename;
}
-
+
function GetImageDir()
{
global $pathtoroot;
-
+
$p = $this->Get("ThumbPath");
if(strlen($p))
{
$parts = pathinfo($pathtoroot.$p);
$d = $parts["dirname"]."/";
}
-
+
if($this->Pending)
- $d .= "pending/";
-
- return $d;
+ $d .= "pending/";
+
+ return $d;
}
-
-
+
+
function Delete()
- {
- $this->DeleteLocalImage();
- parent::Delete();
+ {
+ $this->DeleteLocalImage();
+ parent::Delete();
}
+
+ function Update($UpdatedBy=NULL,$modificationDate = null)
+ {
+ global $Errors, $objSession;
+
+ if(count($this->m_dirtyFieldsMap) == 0)
+ return true;
+
+ $this->SetModified($UpdatedBy,$modificationDate);
+ $sql = "UPDATE ".$this->tablename ." SET ";
+ $first = 1;
+ foreach ($this->m_dirtyFieldsMap as $key => $value)
+ {
+ if(!is_numeric($key) && $key != $this->IdField())
+ {
+ if($first)
+ {
+ if(isset($GLOBALS['_CopyFromEditTable']))
+ $sql = sprintf("%s %s=%s",$sql,$key,$this->adodbConnection->qstr(($value)));
+ else
+ $sql = sprintf("%s %s=%s",$sql,$key,$this->adodbConnection->qstr(stripslashes($value)));
+ $first = 0;
+ }
+ else
+ {
+ if(isset($GLOBALS['_CopyFromEditTable']))
+ $sql = sprintf("%s, %s=%s",$sql,$key,$this->adodbConnection->qstr(($value)));
+ else
+ $sql = sprintf("%s, %s=%s",$sql,$key,$this->adodbConnection->qstr(stripslashes($value)));
+ }
+ }
+ }
+
+ $sql = sprintf("%s WHERE %s = '%s'",$sql, $this->IdField(), $this->UniqueId());
+
+ if($this->debuglevel>0)
+ echo $sql."<br>";
+ if ($this->adodbConnection->Execute($sql) === false)
+ {
+ $Errors->AddError("error.DatabaseError",NULL,$this->adodbConnection->ErrorMsg(),"",get_class($this),"Update");
+ return false;
+ }
+
+ if ($objSession->GetVariable("HasChanges") == 2) {
+ $objSession->SetVariable("HasChanges", 1);
+ }
+
+ /* if ($this->adodbConnection->Affected_Rows() > 0) {
+ $objSession->SetVariable("HasChanges", 1);
+ }*/
+
+ return true;
+ }
+
function LoadFromDatabase($Id)
- {
- global $Errors;
+ {
+ global $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 ImageId = '%s'",$Id);
+
+ $result = $this->adodbConnection->Execute($sql);
+ if ($result === false || $result->EOF)
+ {
+ $Errors->AddError("error.DatabaseError",NULL,$this->adodbConnection->ErrorMsg(),"",get_class($this),"LoadFromDatabase");
+ return false;
+ }
- 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 ImageId = '%s'",$Id);
-
- $result = $this->adodbConnection->Execute($sql);
- if ($result === false || $result->EOF)
- {
- $Errors->AddError("error.DatabaseError",NULL,$this->adodbConnection->ErrorMsg(),"",get_class($this),"LoadFromDatabase");
- return false;
- }
-
$data = $result->fields;
-
- $this->SetFromArray($data);
- $this->Clean();
- return true;
- }
+
+ $this->SetFromArray($data);
+ $this->Clean();
+ return true;
+ }
function LoadFromResource($Id,$ImageIndex)
- {
- global $Errors;
+ {
+ global $Errors;
- if(!isset($Id) || !isset($ImageIndex))
- {
- $Errors->AddError("error.AppError",NULL,'Internal error: LoadFromDatabase id',"",get_class($this),"LoadFromResource");
- return false;
- }
-
- $sql = sprintf("SELECT * FROM ".$this->tablename." WHERE ResourceId = '%s'AND ImageIndex = '%s'",$Id,$ImageIndex);
-
- $result = $this->adodbConnection->Execute($sql);
- if ($result === false || $result->EOF)
- {
-// $Errors->AddError("error.DatabaseError",NULL,$this->adodbConnection->ErrorMsg(),"",get_class($this),"LoadFromResource");
- return false;
- }
+ if(!isset($Id) || !isset($ImageIndex))
+ {
+ $Errors->AddError("error.AppError",NULL,'Internal error: LoadFromDatabase id',"",get_class($this),"LoadFromResource");
+ return false;
+ }
+
+ $sql = sprintf("SELECT * FROM ".$this->tablename." WHERE ResourceId = '%s'AND ImageIndex = '%s'",$Id,$ImageIndex);
+
+ $result = $this->adodbConnection->Execute($sql);
+ if ($result === false || $result->EOF)
+ {
+ // $Errors->AddError("error.DatabaseError",NULL,$this->adodbConnection->ErrorMsg(),"",get_class($this),"LoadFromResource");
+ return false;
+ }
$data = $result->fields;
- $this->SetFromArray($data);
+ $this->SetFromArray($data);
- return true;
- }
+ return true;
+ }
- function LocalImageExists()
- {
- global $objConfig, $pathtoroot;
- $result=FALSE;
- if($this->Get("LocalImage")==1 && $this->Get("SameImages")==0)
- {
+ function LocalImageExists()
+ {
+ global $objConfig, $pathtoroot;
+ $result=FALSE;
+ if($this->Get("LocalImage")==1 && $this->Get("SameImages")==0)
+ {
$imagepath = $pathtoroot.$this->Get("LocalPath");
-// $imagepath = $this->GetImageDir().$this->GetFileName();
-
-// echo "PATH: ".$this->GetImageDir()."; FILE: ".$this->GetFileName()."<BR>";
-
- if(strlen($imagepath)>0)
- {
- $result = file_exists($imagepath);
- }
- }
- return $result;
- }
-
- function LocalThumbExists()
- {
- $result=FALSE;
- global $objConfig, $pathtoroot;
-
- if($this->Get("LocalThumb")==1)
- {
- //$imagepath = $pathtoroot.$this->Get("ThumbPath");
- $imagepath = $this->GetImageDir().$this->GetFileName(1);
- if(strlen($imagepath)>0)
- {
- $result = file_exists($imagepath);
- }
- }
- return $result;
- }
-
-
- function DeleteLocalImage($Thumb=TRUE,$Full=TRUE)
- {
- global $pathtoroot;
-
- if($Full)
- {
- if($this->LocalImageExists())
- {
-// $filename = $this->GetImageDir().$this->GetFileName();
- $filename = $pathtoroot.$this->Get("LocalPath");
-// echo "FULL: $filename<BR>\n";
- @unlink($filename);
- }
- }
-
- if($Thumb)
- {
- if($this->LocalThumbExists())
- {
- $filename = $this->GetImageDir().$this->GetFileName(1);
-// echo "THUMB: $filename<BR>\n";
- @unlink($filename);
- }
- }
- }
-
- function StoreUploadedImage($file, $rewrite_name=1,$DestDir,$IsThumb=0,$IsUpload=TRUE)
- {
- /* move the uploaded image to its final location and update the LocalPath property */
- /* returns the destination filename on success */
- global $objConfig,$pathtoroot;
-
- $Dest_Dir = $DestDir;
- if($this->Pending)
- $Dest_Dir .= "pending/";
-
- if(((int)$file["error"]==0) && (substr($file["type"],0,6)=="image/") && @getimagesize($file["tmp_name"]) )
- {
- $parts = pathinfo($file["name"]);
- $ext = strtolower($parts["extension"]);
-
- if( $GLOBALS['debuglevel'] ) echo "Processing ".$file["tmp_name"]."<br>\n";
+ // $imagepath = $this->GetImageDir().$this->GetFileName();
+
+ // echo "PATH: ".$this->GetImageDir()."; FILE: ".$this->GetFileName()."<BR>";
+
+ if(strlen($imagepath)>0)
+ {
+ $result = file_exists($imagepath);
+ }
+ }
+ return $result;
+ }
+
+ function LocalThumbExists()
+ {
+ $result=FALSE;
+ global $objConfig, $pathtoroot;
+
+ if($this->Get("LocalThumb")==1)
+ {
+ //$imagepath = $pathtoroot.$this->Get("ThumbPath");
+ $imagepath = $this->GetImageDir().$this->GetFileName(1);
+ if(strlen($imagepath)>0)
+ {
+ $result = file_exists($imagepath);
+ }
+ }
+ return $result;
+ }
+
+
+ function DeleteLocalImage($Thumb=TRUE,$Full=TRUE)
+ {
+ global $pathtoroot;
+
+ if($Full)
+ {
+ if($this->LocalImageExists())
+ {
+ // $filename = $this->GetImageDir().$this->GetFileName();
+ $filename = $pathtoroot.$this->Get("LocalPath");
+ // echo "FULL: $filename<BR>\n";
+ @unlink($filename);
+ }
+ }
+
+ if($Thumb)
+ {
+ if($this->LocalThumbExists())
+ {
+ $filename = $this->GetImageDir().$this->GetFileName(1);
+ // echo "THUMB: $filename<BR>\n";
+ @unlink($filename);
+ }
+ }
+ }
+
+ function StoreUploadedImage($file, $rewrite_name=1,$DestDir,$IsThumb=0,$IsUpload=TRUE)
+ {
+ /* move the uploaded image to its final location and update the LocalPath property */
+ /* returns the destination filename on success */
+ global $objConfig,$pathtoroot;
+
+ $Dest_Dir = $DestDir;
+ if($this->Pending)
+ $Dest_Dir .= "pending/";
+
+ if(((int)$file["error"]==0) && (substr($file["type"],0,6)=="image/") && @getimagesize($file["tmp_name"]) )
+ {
+ $parts = pathinfo($file["name"]);
+ $ext = strtolower($parts["extension"]);
+
+ if( $GLOBALS['debuglevel'] ) echo "Processing ".$file["tmp_name"]."<br>\n";
+
+ if($rewrite_name==1)
+ {
+
+ if($IsThumb)
+ $filename = "th_";
+ $filename .= $this->Get("ResourceId")."_".$this->Get("ImageIndex").".".$ext;
+ }
+ else
+ {
+ $filename = $file["name"];
+ }
+ $destination = $pathtoroot.$Dest_Dir.$filename;
+ if( $GLOBALS['debuglevel'] ) echo $file["tmp_name"]."=>".$destination."<br>\n";
+ if($IsUpload==TRUE)
+ {
+ $result = @move_uploaded_file($file["tmp_name"],$destination);
+ }
+ else
+ $result = copy($file["tmp_name"],$destination);
+ if($result)
+ {
+ @chmod($Dest_Dir.$filename, 0666);
+ return $Dest_Dir.$filename;
+ }
+ else
+ return "";
+ }
+ else
+ return "";
+ }
+
+ function CopyToPending()
+ {
+ global $pathtoroot;
+
+ $ThumbPath = (strlen($this->Get("ThumbPath"))>0) ? $pathtoroot.$this->Get("ThumbPath") : '';
+ $FullPath = strlen($this->Get("LocalPath")) ? $pathtoroot.$this->Get("LocalPath") : '';
+
+ $dest = $this->GetImageDir()."pending/";
+
+
+ // echo "DESTIN DIR: $dest<BR>";
+ // echo "THUMB PATH: $ThumbPath <BR>";
+
+ if(strlen($ThumbPath))
+ {
+ if(file_exists($ThumbPath))
+ {
+ $p = pathinfo($ThumbPath);
+ $d = $dest.$p["basename"];
+ if(file_exists($d))
+ unlink($d);
+ copy($ThumbPath,$d);
+ @chmod($ThumbPath.$d, 0666);
+ }
+ }
+
+
+ if(strlen($FullPath))
+ {
+ if(file_exists($FullPath))
+ {
+ $p = pathinfo($FullPath);
+ $d = $dest.$p["basename"];
+ if(file_exists($d))
+ unlink($d);
+ copy($FullPath,$d);
+ @chmod($FullPath.$d, 0666);
+ }
+ }
+ }
+
+ function CopyFromPending()
+ {
+ global $pathtoroot,$pathchar;
+
+ $ThumbPath = $this->Get("ThumbPath");
+ $FullPath = $this->Get("LocalPath");
+
+ // $src = $this->GetImageDir()."pending/";
+ $src = $this->GetImageDir();
+
+ if(strlen($ThumbPath))
+ {
+ if(strpos($ThumbPath,"pending/"))
+ {
+ if(file_exists($pathtoroot.$ThumbPath))
+ {
+ $path = pathinfo($pathtoroot.$ThumbPath);
+ $p = explode("/",$ThumbPath);
+ unset($p[count($p)-2]);
+
+ $d = $pathtoroot.implode("/",$p);
+
+ if(file_exists($d))
+ unlink($d);
+
+ copy($pathtoroot.$ThumbPath,$d);
+ @chmod($pathtoroot.$ThumbPath.$d, 0666);
+ unlink($pathtoroot.$ThumbPath);
+ }
+
+ }
+ }
+ if(strlen($FullPath))
+ {
+ if(file_exists($pathtoroot.$FullPath))
+ {
+ if(strpos($FullPath,"pending/"))
+ {
+ $path = pathinfo($pathtoroot.$FullPath);
+ $p = explode("/",$FullPath);
+ unset($p[count($p)-2]);
+
+ $d = $pathtoroot.implode("/",$p);
+
+ if(file_exists($d))
+ unlink($d);
+ copy($pathtoroot.$FullPath,$d);
+ @chmod($pathtoroot.$FullPath.$d, 0666);
+ unlink($pathtoroot.$FullPath);
+ }
+ }
+ }
+ }
- if($rewrite_name==1)
- {
+ function DeleteFromPending()
+ {
+ global $pathtoroot;
+ $ThumbPath = $pathtoroot.$this->Get("ThumbPath");
+ $FullPath = $pathtoroot.$this->Get("LocalPath");
- if($IsThumb)
- $filename = "th_";
- $filename .= $this->Get("ResourceId")."_".$this->Get("ImageIndex").".".$ext;
- }
- else
- {
- $filename = $file["name"];
- }
- $destination = $pathtoroot.$Dest_Dir.$filename;
- if( $GLOBALS['debuglevel'] ) echo $file["tmp_name"]."=>".$destination."<br>\n";
- if($IsUpload==TRUE)
- {
- $result = @move_uploaded_file($file["tmp_name"],$destination);
- }
- else
- $result = copy($file["tmp_name"],$destination);
- if($result)
- {
- @chmod($Dest_Dir.$filename, 0666);
- return $Dest_Dir.$filename;
- }
- else
- return "";
- }
- else
- return "";
- }
-
- function CopyToPending()
- {
- global $pathtoroot;
-
- $ThumbPath = (strlen($this->Get("ThumbPath"))>0) ? $pathtoroot.$this->Get("ThumbPath") : '';
- $FullPath = strlen($this->Get("LocalPath")) ? $pathtoroot.$this->Get("LocalPath") : '';
-
- $dest = $this->GetImageDir()."pending/";
-
-
-// echo "DESTIN DIR: $dest<BR>";
-// echo "THUMB PATH: $ThumbPath <BR>";
-
- if(strlen($ThumbPath))
- {
- if(file_exists($ThumbPath))
- {
- $p = pathinfo($ThumbPath);
- $d = $dest.$p["basename"];
- if(file_exists($d))
- unlink($d);
- copy($ThumbPath,$d);
- @chmod($ThumbPath.$d, 0666);
- }
- }
-
-
- if(strlen($FullPath))
- {
- if(file_exists($FullPath))
- {
- $p = pathinfo($FullPath);
- $d = $dest.$p["basename"];
- if(file_exists($d))
- unlink($d);
- copy($FullPath,$d);
- @chmod($FullPath.$d, 0666);
- }
- }
- }
-
- function CopyFromPending()
- {
- global $pathtoroot,$pathchar;
-
- $ThumbPath = $this->Get("ThumbPath");
- $FullPath = $this->Get("LocalPath");
-
-// $src = $this->GetImageDir()."pending/";
- $src = $this->GetImageDir();
-
- if(strlen($ThumbPath))
- {
- if(strpos($ThumbPath,"pending/"))
- {
- if(file_exists($pathtoroot.$ThumbPath))
- {
- $path = pathinfo($pathtoroot.$ThumbPath);
- $p = explode("/",$ThumbPath);
- unset($p[count($p)-2]);
-
- $d = $pathtoroot.implode("/",$p);
-
- if(file_exists($d))
- unlink($d);
-
- copy($pathtoroot.$ThumbPath,$d);
- @chmod($pathtoroot.$ThumbPath.$d, 0666);
- unlink($pathtoroot.$ThumbPath);
- }
-
- }
- }
- if(strlen($FullPath))
- {
- if(file_exists($pathtoroot.$FullPath))
- {
- if(strpos($FullPath,"pending/"))
- {
- $path = pathinfo($pathtoroot.$FullPath);
- $p = explode("/",$FullPath);
- unset($p[count($p)-2]);
-
- $d = $pathtoroot.implode("/",$p);
-
- if(file_exists($d))
- unlink($d);
- copy($pathtoroot.$FullPath,$d);
- @chmod($pathtoroot.$FullPath.$d, 0666);
- unlink($pathtoroot.$FullPath);
- }
- }
- }
- }
-
- function DeleteFromPending()
- {
- global $pathtoroot;
- $ThumbPath = $pathtoroot.$this->Get("ThumbPath");
- $FullPath = $pathtoroot.$this->Get("LocalPath");
-
- $src = $this->GetImageDir()."pending/";
- $p = pathinfo($ThumbPath);
- $d = $src.$p["basename"];
+ $src = $this->GetImageDir()."pending/";
+ $p = pathinfo($ThumbPath);
+ $d = $src.$p["basename"];
if(file_exists($d))
- @unlink($d);
+ @unlink($d);
- $p = pathinfo($FullPath);
- $d = $src.$p["basename"];
+ $p = pathinfo($FullPath);
+ $d = $src.$p["basename"];
if(file_exists($d))
- @unlink($d);
- }
+ @unlink($d);
+ }
+
+ function RenameFiles($OldResId,$NewResId)
+ {
+ global $pathtoroot;
+
+ if($this->Pending)
+ {
+ $ThumbPath = $this->GetImageDir().$this->GetFileName(TRUE);
+ }
+ else
+ $ThumbPath = $pathtoroot.$this->Get("ThumbPath");
+ $parts = pathinfo($ThumbPath);
+ $ext = $parts["extension"];
+ $pending="";
+ if($this->Pending)
+ {
+ $pending="pending/";
+ $FullPath = $this->GetImageDir().$this->GetFileName(FALSE);
+ }
+ else
+ $FullPath = $pathtoroot.$this->Get("LocalPath");
+
+ $NewThumb = $pathtoroot."kernel/images/".$pending."th_$NewResId_".$this->Get("ImageIndex").".$ext";
+ $NewFull = $pathtoroot."kernel/images/".$pending."$NewResId_".$this->Get("ImageIndex").".$ext";
+ if(file_exists($ThumbPath))
+ {
+ @rename($ThumbPath,$NewThumb);
+ }
+
+ if(file_exists($FullPath))
+ {
+ @rename($FullPath,$NewFull);
+ }
+
+ }
+
+ function ReplaceImageFile($file)
+ {
+ global $objConfig;
+
+ if($file["error"]==0)
+ {
+ $this->DeleteLocalImage();
+ move_uploaded_file($file,$this->Get("LocalPath"));
+ @chmod($this->Get("LocalPath"), 0666);
+ }
+ }
+
+ function FullURL($ForceNoThumb=FALSE,$Default="kernel/images/noimage.gif")
+ {
+ global $rootURL, $objConfig,$pathtoroot;
+
+ if($this->Get("SameImages") && !$ForceNoThumb)
+ return $this->ThumbURL();
+
+ if(strlen($this->Get("Url")))
+ return $this->Get("Url");
+ if($this->Get("LocalImage")=="1")
+ {
+ $url = $this->Get("LocalPath");
+ //$url = $this->GetImageDir().$this->GetFileName();
+ if(file_exists($pathtoroot.$url))
+ {
+ if(strlen($url))
+ {
+ $url = $rootURL.$url;
+ return $url;
+ }
+ else
+ {
+ if(strlen($Default))
+ $url = $rootURL.$Default;
+ return $url;
+ }
+ }
+ else
+ {
+ if(strlen($Default))
+ {
+ return $rootURL.$Default;
+ }
+ else
+ return "";
+ }
+ }
+ else
+ {
+ if(strlen($Default))
+ {
+ return $rootURL.$Default;
+ }
+ else
+ return "";
+ }
+ }
+
+ function ThumbURL()
+ {
+ global $rootURL, $pathtoroot, $objConfig;
+
+ if(strlen($this->Get("ThumbUrl")))
+ return $this->Get("ThumbUrl");
+
+ if($this->Get("LocalThumb")=="1")
+ {
+ $url = $this->Get("ThumbPath");
+ //$url = $this->GetImageDir().$this->GetFileName();
+ if(file_exists($pathtoroot.$url))
+ {
+ if(strlen($url))
+ {
+ $url = $rootURL.$url;
+ }
+ else
+ $url = $rootURL."kernel/images/noimage.gif";
+ return $url;
+ }
+ else
+ return $rootURL."kernel/images/noimage.gif";
+ }
+ else
+ return $rootURL."kernel/images/noimage.gif";
+ }
+
+ function ParseObject($element)
+ {
+ $extra_attribs = ExtraAttributes($element->attributes);
+ if(strtolower($element->name)==$this->TagPrefix)
+ {
+ $field = strtolower($element->attributes["_field"]);
+ switch($field)
+ {
+ case "name":
+ $ret = $this->Get("Name");
+ break;
+ case "alt":
+ $ret = $this->Get("AltName");
+ break;
+ case "full_url":
+ $ret = $this->FullURL();
+ break;
+ case "thumb_url":
+ $ret = $this->ThumbURL();
+ break;
+ }
+ }
+ else
+ $ret = $element->Execute();
+ return $ret;
+ }
+
+ function parsetag($tag)
+ {
+ if(is_object($tag))
+ {
+ $tagname = $tag->name;
+ }
+ else
+ $tagname = $tag;
+ switch($tagname)
+ {
+ case "image_name":
+ $ret = $this->Get("Name");
+ break;
+ case "image_alt":
+ $ret = $this->Get("AltName");
+ break;
+ case "image_url":
+ $ret = $this->FullURL();
+ break;
+ case "thumb_url":
+ $ret = $this->ThumbURL();
+ break;
+ }
+ return $ret;
+ }
+
+ //Changes priority
+ function MoveUp()
+ {
+ $this->Increment("Priority");
+ }
+
+ function MoveDown()
+ {
+ $this->Decrement("Priority");
+ }
+
+ function GetMaxPriority()
+ {
+ $SourceId = $this->Get("ResourceId");
+ $sql = "SELECT MAX(Priority) as p from ".$this->tablename."WHERE ResourceId=$SourceId";
+ $result = $this->adodbConnection->Execute($sql);
+ return $result->fields["p"];
+ }
- function RenameFiles($OldResId,$NewResId)
- {
- global $pathtoroot;
-
- if($this->Pending)
- {
- $ThumbPath = $this->GetImageDir().$this->GetFileName(TRUE);
- }
- else
- $ThumbPath = $pathtoroot.$this->Get("ThumbPath");
- $parts = pathinfo($ThumbPath);
- $ext = $parts["extension"];
- $pending="";
- if($this->Pending)
- {
- $pending="pending/";
- $FullPath = $this->GetImageDir().$this->GetFileName(FALSE);
- }
- else
- $FullPath = $pathtoroot.$this->Get("LocalPath");
-
- $NewThumb = $pathtoroot."kernel/images/".$pending."th_$NewResId_".$this->Get("ImageIndex").".$ext";
- $NewFull = $pathtoroot."kernel/images/".$pending."$NewResId_".$this->Get("ImageIndex").".$ext";
- if(file_exists($ThumbPath))
- {
- @rename($ThumbPath,$NewThumb);
- }
-
- if(file_exists($FullPath))
- {
- @rename($FullPath,$NewFull);
- }
-
- }
-
- function ReplaceImageFile($file)
- {
- global $objConfig;
-
- if($file["error"]==0)
- {
- $this->DeleteLocalImage();
- move_uploaded_file($file,$this->Get("LocalPath"));
- @chmod($this->Get("LocalPath"), 0666);
- }
- }
-
- function FullURL($ForceNoThumb=FALSE,$Default="kernel/images/noimage.gif")
- {
- global $rootURL, $objConfig,$pathtoroot;
-
- if($this->Get("SameImages") && !$ForceNoThumb)
- return $this->ThumbURL();
-
- if(strlen($this->Get("Url")))
- return $this->Get("Url");
- if($this->Get("LocalImage")=="1")
- {
- $url = $this->Get("LocalPath");
- //$url = $this->GetImageDir().$this->GetFileName();
- if(file_exists($pathtoroot.$url))
- {
- if(strlen($url))
- {
- $url = $rootURL.$url;
- return $url;
- }
- else
- {
- if(strlen($Default))
- $url = $rootURL.$Default;
- return $url;
- }
- }
- else
- {
- if(strlen($Default))
- {
- return $rootURL.$Default;
- }
- else
- return "";
- }
- }
- else
- {
- if(strlen($Default))
- {
- return $rootURL.$Default;
- }
- else
- return "";
- }
- }
-
- function ThumbURL()
- {
- global $rootURL, $pathtoroot, $objConfig;
-
- if(strlen($this->Get("ThumbUrl")))
- return $this->Get("ThumbUrl");
-
- if($this->Get("LocalThumb")=="1")
- {
- $url = $this->Get("ThumbPath");
- //$url = $this->GetImageDir().$this->GetFileName();
- if(file_exists($pathtoroot.$url))
- {
- if(strlen($url))
- {
- $url = $rootURL.$url;
- }
- else
- $url = $rootURL."kernel/images/noimage.gif";
- return $url;
- }
- else
- return $rootURL."kernel/images/noimage.gif";
- }
- else
- return $rootURL."kernel/images/noimage.gif";
- }
-
- function ParseObject($element)
- {
- $extra_attribs = ExtraAttributes($element->attributes);
- if(strtolower($element->name)==$this->TagPrefix)
- {
- $field = strtolower($element->attributes["_field"]);
- switch($field)
- {
- case "name":
- $ret = $this->Get("Name");
- break;
- case "alt":
- $ret = $this->Get("AltName");
- break;
- case "full_url":
- $ret = $this->FullURL();
- break;
- case "thumb_url":
- $ret = $this->ThumbURL();
- break;
- }
- }
- else
- $ret = $element->Execute();
- return $ret;
- }
-
- function parsetag($tag)
- {
- if(is_object($tag))
- {
- $tagname = $tag->name;
- }
- else
- $tagname = $tag;
- switch($tagname)
- {
- case "image_name":
- $ret = $this->Get("Name");
- break;
- case "image_alt":
- $ret = $this->Get("AltName");
- break;
- case "image_url":
- $ret = $this->FullURL();
- break;
- case "thumb_url":
- $ret = $this->ThumbURL();
- break;
- }
- return $ret;
- }
-
- //Changes priority
- function MoveUp()
- {
- $this->Increment("Priority");
- }
-
- function MoveDown()
- {
- $this->Decrement("Priority");
- }
-
- function GetMaxPriority()
- {
- $SourceId = $this->Get("ResourceId");
- $sql = "SELECT MAX(Priority) as p from ".$this->tablename."WHERE ResourceId=$SourceId";
- $result = $this->adodbConnection->Execute($sql);
- return $result->fields["p"];
- }
-
- function GetMinPriority()
- {
- $SourceId = $this->Get("ResourceId");
- $sql = "SELECT MIN(Priority) as p from ".$this->tablename."WHERE ResourceId=$SourceId";
- $result = $this->adodbConnection->Execute($sql);
- return $result->fields["p"];
- }
-
- function UpdatePriority()
- {
- $SourceId = $this->Get("ResourceId");
- $sql = "SELECT MAX(Priority) as p from ".$this->tablename."WHERE ReourceId=$SourceId";
- $result = $this->adodbConnection->Execute($sql);
- $this->Set("Priority", $result->fields["p"]+1);
- }
+ function GetMinPriority()
+ {
+ $SourceId = $this->Get("ResourceId");
+ $sql = "SELECT MIN(Priority) as p from ".$this->tablename."WHERE ResourceId=$SourceId";
+ $result = $this->adodbConnection->Execute($sql);
+ return $result->fields["p"];
+ }
+
+ function UpdatePriority()
+ {
+ $SourceId = $this->Get("ResourceId");
+ $sql = "SELECT MAX(Priority) as p from ".$this->tablename."WHERE ReourceId=$SourceId";
+ $result = $this->adodbConnection->Execute($sql);
+ $this->Set("Priority", $result->fields["p"]+1);
+ }
}
class clsImageList extends clsItemCollection
{
- var $Page;
- var $PerPageVar;
+ var $Page;
+ var $PerPageVar;
+
+ function clsImageList()
+ {
+ $this->clsItemCollection();
+ $this->PerPageVar = "Perpage_Images";
+ $this->SourceTable = GetTablePrefix()."Images";
+ $this->classname = "clsImage";
+ }
+
+ function LoadImages($where="",$orderBy = "")
+ {
+ global $objConfig;
+
+ $this->Clear();
+ if($this->Page<1)
+ $this->Page=1;
+
+ if(is_numeric($objConfig->Get("Perpage_Images")))
+ {
+ $Start = ($this->Page-1)*$objConfig->Get("Perpage_Images");
+ $limit = "LIMIT ".$Start.",".$objConfig->Get("Perpage_Images");
+ }
+ else
+ $limit = NULL;
+
+
+ $this->QueryItemCount=TableCount("Images",$where,0);
+ //echo $this->QueryItemCount."<br>\n";
+ if(strlen(trim($orderBy))>0)
+ {
+ $orderBy = "Priority DESC, ".$orderBy;
+ }
+ else
+ $orderBy = "Priority DESC";
+
+ return $this->Query_Images($where,$orderBy,$limit);
+ }
+
+ function Query_Images($whereClause,$orderByClause=NULL,$limit=NULL)
+ {
+ global $objSession, $Errors;
+
+ $sql = "SELECT * FROM ".$this->SourceTable;
+
+ if(isset($whereClause))
+ $sql = sprintf('%s WHERE %s',$sql,$whereClause);
+ if(isset($orderByClause) && strlen(trim($orderByClause))>0)
+ $sql = sprintf('%s ORDER BY %s',$sql,$orderByClause);
+ if(isset($limit) && strlen(trim($limit)))
+ $sql .= " ".$limit;
+ //echo $sql;
+ return $this->Query_Item($sql);
+ }
- function clsImageList()
- {
- $this->clsItemCollection();
- $this->PerPageVar = "Perpage_Images";
- $this->SourceTable = GetTablePrefix()."Images";
- $this->classname = "clsImage";
- }
-
- function LoadImages($where="",$orderBy = "")
- {
- global $objConfig;
-
- $this->Clear();
- if($this->Page<1)
- $this->Page=1;
-
- if(is_numeric($objConfig->Get("Perpage_Images")))
- {
- $Start = ($this->Page-1)*$objConfig->Get("Perpage_Images");
- $limit = "LIMIT ".$Start.",".$objConfig->Get("Perpage_Images");
- }
- else
- $limit = NULL;
-
-
- $this->QueryItemCount=TableCount("Images",$where,0);
- //echo $this->QueryItemCount."<br>\n";
- if(strlen(trim($orderBy))>0)
- {
- $orderBy = "Priority DESC, ".$orderBy;
- }
- else
- $orderBy = "Priority DESC";
-
- return $this->Query_Images($where,$orderBy,$limit);
- }
-
- function Query_Images($whereClause,$orderByClause=NULL,$limit=NULL)
- {
- global $objSession, $Errors;
-
- $sql = "SELECT * FROM ".$this->SourceTable;
-
- if(isset($whereClause))
- $sql = sprintf('%s WHERE %s',$sql,$whereClause);
- if(isset($orderByClause) && strlen(trim($orderByClause))>0)
- $sql = sprintf('%s ORDER BY %s',$sql,$orderByClause);
- if(isset($limit) && strlen(trim($limit)))
- $sql .= " ".$limit;
- //echo $sql;
- return $this->Query_Item($sql);
- }
-
- function &Add($Name, $Alt, $ResourceId, $LocalImage, $LocalThumb,
- $Url, $ThumbUrl, $Enabled=1, $Priority=0, $DefaultImg=0, $ImageIndex=0,
- $SameImages=0, $ImageId=-999)
- {
+ function &Add($Name, $Alt, $ResourceId, $LocalImage, $LocalThumb,
+ $Url, $ThumbUrl, $Enabled=1, $Priority=0, $DefaultImg=0, $ImageIndex=0,
+ $SameImages=0, $ImageId=-999)
+ {
if($DefaultImg==1)
{
- $sql = "UPDATE ".$this->SourceTable." SET DefaultImg=0 WHERE ResourceId=$ResourceId";
- $this->adodbConnection->Execute($sql);
- }
-
- $img = new clsImage();
- $img->tablename = $this->SourceTable;
- $img->Set(array("Name","AltName","ResourceId","LocalImage","LocalThumb",
- "Url","ThumbUrl","Enabled","Priority","DefaultImg","ImageIndex","SameImages"),
- array($Name,$Alt,$ResourceId,$LocalImage,$LocalThumb,
- $Url,$ThumbUrl,$Enabled,$Priority,$DefaultImg,$ImageIndex,$SameImages));
-
- if ($ImageId != -999)
- {
- $img->Set("ImageId", $ImageId);
- }
-
- if((int)$ImageIndex==0)
- $img->Set("ImageIndex",$this->GetNextImageIndex($ResourceId));
- $img->Create();
- array_push($this->Items,$img);
- return $img;
- }
-
-
- function Edit($ImageId,$Name, $Alt, $ResourceId, $LocalImage, $LocalThumb,
- $Url, $ThumbUrl, $Enabled=1, $Priority=0, $DefaultImg=0, $ImageIndex=0,
- $SameImages=0)
- {
- $img = $this->GetItem($ImageId);
-
- if((int)$ImageIndex==0)
- $ImageIndex = $img->Get("ImageIndex");
-
- if(!strlen($ThumbUrl) && !$LocalThumb)
- $ThumbUrl = $img->Get("ThumbUrl");
-
- $img->Set(array("Name","AltName","ResourceId","LocalImage","LocalThumb",
- "Url","ThumbUrl","Enabled","Priority","DefaultImg","ImageIndex","SameImages"),
- array($Name, $Alt, $ResourceId, $LocalImage, $LocalThumb,
- $Url, $ThumbUrl, $Enabled, $Priority, $DefaultImg, $ImageIndex,$SameImages));
-
- if((int)$ImageIndex==0)
- $img->Set("ImageIndex",$this->GetNextImageIndex($ResourceId));
-
- $img->Update();
-
- if($DefaultImg==1)
- {
- $sql = "UPDATE ".$this->SourceTable." SET DefaultImg=0 WHERE ResourceId=".$ResourceId." AND ImageId !=$ImageId";
- $this->adodbConnection->Execute($sql);
- }
- array_push($this->Items,$img);
-
- return $img;
- }
-
- function Delete_Image($ImageId)
- {
- $i = $this->GetItem($ImageId);
- $i->Delete();
- }
-
- function DeleteResource($ResourceId)
- {
- $this->Clear();
- $images = $this->Query_Images("ResourceId=".$ResourceId);
- if(is_array($images))
- {
- foreach($images as $i)
- {
- $i->Delete();
- }
- }
- }
-
- function LoadResource($ResourceId)
- {
- $sql = "SELECT * FROM ".$this->SourceTable." WHERE ResourceId=$ResourceId";
- $this->Query_Item($sql);
- }
-
- function CopyResource($SourceId,$DestId)
- {
- global $pathtoroot;
-
- $this->Clear();
- $this->LoadResource($SourceId);
- foreach($this->Items as $i)
- {
- if($i->Get("LocalThumb"))
- {
- $f = $pathtoroot.$i->Get("ThumbPath");
- if(file_exists($f))
- {
- $p = pathinfo($f);
- $dir = $p["dirname"];
- $ext = $p["extension"];
- $newfile = $dir."/th_".$DestId."_".$i->Get("ImageIndex").".".$ext;
- if(file_exists($newfile))
- @unlink($newfile);
-// echo $f." -> ".$newfile;
- copy($f,$newfile);
- }
- }
- if($i->Get("LocalImage"))
- {
- $f = $pathtoroot.$i->Get("LocalPath");
- if(file_exists($f))
- {
- $p = pathinfo($f);
- $dir = $p["dirname"];
- $ext = $p["extension"];
- $newfile = $dir."/".$DestId."_".$i->Get("ImageIndex").".".$ext;
- if(file_exists($newfile))
- @unlink($newfile);
-
-// echo $f." -> ".$newfile;
- copy($f,$newfile);
- }
- }
- }
- parent::CopyResource($SourceId,$DestId);
- $this->Clear();
- $this->LoadResource($DestId);
- foreach($this->Items as $img)
- {
- if($img->Get("LocalThumb"))
- {
- $f = str_replace("th_$SourceId","th_$DestId",$img->Get("ThumbPath"));
- $img->Set("ThumbPath",$f);
- }
- if($img->Get("LocalImage"))
- {
- $f = str_replace("/".$SourceId."_","/".$DestId."_",$img->Get("LocalPath"));
- $img->Set("LocalPath",$f);
- }
- $img->Update();
- }
- }
-
- function GetImageByResource($ResourceId,$Index)
- {
- $found=FALSE;
- if($this->NumItems()>0)
- {
- foreach($this->Items as $i)
- {
- if($i->Get("ResourceID")==$ResourceId and ($i->Get("ImageIndex")==$Index))
- {
- $found=TRUE;
- break;
- }
- }
- }
- if(!$found)
- {
- $i = NULL;
- $i = new clsImage();
- if($i->LoadFromResource($ResourceId,$Index))
- {
- array_push($this->Items, $i);
- }
- else
- unset($i);
- }
- if(is_object($i))
- {
- return $i;
- }
- else
- return FALSE;
- }
-
- function &GetDefaultImage($ResourceId)
- {
- $sql = "SELECT * FROM ".$this->SourceTable." WHERE ResourceId=$ResourceId AND DefaultImg=1";
- $rs = $this->adodbConnection->Execute($sql);
- if($rs && ! $rs->EOF)
- {
- $data = $rs->fields;
- $img= new clsImage();
- $img->SetFromArray($data);
- $img->Clean();
- return $img;
- }
- else
- return FALSE;
-
- }
- function HandleImageUpload($FILE,$ResourceId,$RelatedTo,$DestDir, $Name="",$AltName="",$IsThumb=0)
- {
- global $objConfig;
-
- $img = $this->GetImageByResource($ResourceId,$RelatedTo);
-
- if(is_object($img) && $RelatedTo>0)
- {
- $img->Set("LocalImage",1);
- $img->Set("Name",$Name);
- $img->Set("AltName",$AltName);
- $img->Set("IsThumbnail",$IsThumb);
- $dest = $img->StoreUploadedImage($FILE,1,$DestDir);
- if(strlen($dest))
- {
- $img->Set("Url", $objConfig->Get("Site_Path").$dest);
- $img->Update();
- }
- }
- else
- {
- $img=$this->NewLocalImage($ResourceId,$RelatedTo,$Name,$AltName,$IsThumb,$FILE,$DestDir);
- }
- return $img;
- }
-
- function GetResourceImages($ResourceId)
- {
- $sql = "SELECT * FROM ".$this->SourceTable." WHERE ResourceId=".$ResourceId;
- $rs = $this->adodbConnection->Execute($sql);
- while($rs && !$rs->EOF)
- {
- $img = new clsImage();
- $img->LoadFromResource($ResourceId,$rs->fields["RelatedTo"]);
- array_push($this->Images,$img);
- $rs->MoveNext();
- }
- }
-
- function GetResourceThumbnail($ResourceId)
- {
- $found=FALSE;
- foreach($this->Images as $img)
- {
- if($img->Get("ResourceId")==$ResourceId && $img->Get("IsThumbnail")==1)
- {
- $found=TRUE;
- break;
- }
- }
- if($found)
- {
- return $img;
- }
- else
- return FALSE;
- }
-
- function &GetImageByName($ResourceId,$name)
- {
- $found = FALSE;
- foreach($this->Items as $img)
- {
- if($img->Get("ResourceId")==$ResourceId && $img->Get("Name")==$name)
- {
- $found=TRUE;
- break;
- }
- }
- if($found)
- {
- return $img;
- }
- else
- {
- $sql = "SELECT * FROM ".$this->SourceTable." WHERE ResourceId=$ResourceId AND Name LIKE '$name'";
- //echo $sql;
- $rs = $this->adodbConnection->Execute($sql);
- if($rs && !$rs->EOF)
- {
- $img = $this->AddItemFromArray($rs->fields);
- return $img;
- }
- else
- return FALSE;
- }
- }
-
- function CopyToPendingFiles()
- {
- $sql = "SELECT * FROM ".$this->SourceTable;
- $this->Clear();
- $this->Query_Item($sql);
- foreach($this->Items as $i)
- {
- if(strlen($i->Get("LocalImage")) || strlen($i->Get("LocalThumb")))
- {
- $i->CopyToPending();
- }
- }
- }
-
- function CopyFromPendingFiles($edit_table)
- {
- $sql = "SELECT * FROM ".$edit_table;
- $this->Clear();
- $this->Query_Item($sql);
- foreach($this->Items as $i)
- {
-
- ## Delete original Images
- $OrgImage = new clsImage($i->Get("ImageId"));
- $OrgImage->DeleteLocalImage();
-
- if($i->Get("LocalImage") || $i->Get("LocalThumb"))
- {
- $i->CopyFromPending();
-
- $t = $i->Get("LocalPath");
-
- $p = pathinfo($t);
- $p_arr = explode("/", $p['dirname']);
- if (eregi("pending", $p_arr[count($p_arr)-1]))
- {
- unset($p_arr[count($p_arr)-1]);
- $p['dirname'] = implode("/", $p_arr);
- $LocalPath = $p['dirname']."/".$p['basename'];
- $i->Set("LocalPath", $LocalPath);
- }
-
- $t = $i->Get("ThumbPath");
- $p = pathinfo($t);
-
- $p_arr = explode("/", $p['dirname']);
- if (eregi("pending", $p_arr[count($p_arr)-1]))
- {
- unset($p_arr[count($p_arr)-1]);
- $p['dirname'] = implode("/", $p_arr);
- $ThumbPath = $p['dirname']."/".$p['basename'];
- $i->Set("ThumbPath", $ThumbPath);
- }
-
- $i->tablename = $edit_table;
-
- $update = 1;
- }
-
- ## Empty the fields if are not used
- if (!$i->Get("LocalImage"))
- {
- $i->Set("LocalPath", "");
- $update = 1;
- }
-
- if (!$i->Get("LocalThumb"))
- {
- $i->Set("ThumbPath", "");
- $update = 1;
- }
-
- if ($update)
- $i->Update();
-
- }
- }
-
- function DeletePendingFiles($edit_table)
- {
- $sql = "SELECT * FROM ".$edit_table;
- $this->Clear();
- $this->Query_Item($sql);
- foreach($this->Items as $i)
- {
- $i->DeleteFromPending();
- }
- }
-
- function CopyToEditTable($idfield, $idlist)
- {
- global $objSession;
-
- $edit_table = $objSession->GetEditTable($this->SourceTable);
- @$this->adodbConnection->Execute("DROP TABLE IF EXISTS $edit_table");
- if(is_array($idlist))
- {
- $list = implode(",",$idlist);
- }
- else
- $list = $idlist;
- $query = "SELECT * FROM ".$this->SourceTable." WHERE $idfield IN ($list)";
- $insert = "CREATE TABLE ".$edit_table." ".$query;
- if($objSession->HasSystemPermission("DEBUG.LIST"))
- echo htmlentities($insert,ENT_NOQUOTES)."<br>\n";
- $this->adodbConnection->Execute($insert);
- $this->SourceTable = $edit_table;
- $this->CopyToPendingFiles();
-
- $this->UpdateFilenamesToPendings();
- }
-
- function UpdateFilenamesToPendings()
- {
- global $objSession;
-
- $edit_table = $this->SourceTable;
-
- $sql = "SELECT * FROM ".$edit_table." WHERE (LocalPath!='' AND LocalPath IS NOT NULL) OR (ThumbPath!='' AND ThumbPath IS NOT NULL)";
- $this->Clear();
- $this->Query_Item($sql);
-
- foreach($this->Items as $i)
- {
- $set = "";
- $ImageId = $i->Get("ImageId");
-
- ## Update Local Image Path -> add "pending/" to PATH
- if (strlen($i->Get("LocalPath")))
- {
- $p = pathinfo($i->Get("LocalPath"));
- if (!eregi("/pending $", $p['dirname']))
- {
- $LocalPath = $p['dirname']."/pending/".$p['basename'];
- $set = "SET LocalPath='$LocalPath'";
- }
- }
-
-// echo "LocalImage: ".$i->Get("LocalImage").", PATH: ".$i->Get("LocalPath")."<BR>";
-
- ## Update Local Thumb Path -> add "pending/" to PATH
- if (strlen($i->Get("ThumbPath")))
- {
- $p = pathinfo($i->Get("ThumbPath"));
- if (!eregi("/pending $", $p['dirname']))
- {
- $LocalThumb = $p['dirname']."/pending/".$p['basename'];
- if (strlen($set))
- $set.= ", ThumbPath='$LocalThumb'";
- else
- $set = "SET ThumbPath='$LocalThumb'";
- }
- }
-
-// echo "LocalThumb: ".$i->Get("LocalThumb").", PATH: ".$i->Get("ThumbPath")."<BR>";
-
- if (strlen($set))
- {
- $sql = "UPDATE $edit_table $set WHERE ImageId=$ImageId";
- if($objSession->HasSystemPermission("DEBUG.LIST"))
- echo htmlentities($sql,ENT_NOQUOTES)."<br>\n";
- $this->adodbConnection->Execute($sql);
- }
- }
- }
-
- function CopyFromEditTable($idfield)
- {
- global $objSession;
+ $sql = "UPDATE ".$this->SourceTable." SET DefaultImg=0 WHERE ResourceId=$ResourceId";
+ $this->adodbConnection->Execute($sql);
+ }
+
+ $img = new clsImage();
+ $img->tablename = $this->SourceTable;
+ $img->Set(array("Name","AltName","ResourceId","LocalImage","LocalThumb",
+ "Url","ThumbUrl","Enabled","Priority","DefaultImg","ImageIndex","SameImages"),
+ array($Name,$Alt,$ResourceId,$LocalImage,$LocalThumb,
+ $Url,$ThumbUrl,$Enabled,$Priority,$DefaultImg,$ImageIndex,$SameImages));
+
+ if ($ImageId != -999)
+ {
+ $img->Set("ImageId", $ImageId);
+ }
+
+ if((int)$ImageIndex==0)
+ $img->Set("ImageIndex",$this->GetNextImageIndex($ResourceId));
+ $img->Create();
+ array_push($this->Items,$img);
+ return $img;
+ }
+
+
+ function Edit($ImageId,$Name, $Alt, $ResourceId, $LocalImage, $LocalThumb,
+ $Url, $ThumbUrl, $Enabled=1, $Priority=0, $DefaultImg=0, $ImageIndex=0,
+ $SameImages=0)
+ {
+ $img = $this->GetItem($ImageId);
+
+ if((int)$ImageIndex==0)
+ $ImageIndex = $img->Get("ImageIndex");
+
+ if(!strlen($ThumbUrl) && !$LocalThumb)
+ $ThumbUrl = $img->Get("ThumbUrl");
+
+ $img->Set(array("Name","AltName","ResourceId","LocalImage","LocalThumb",
+ "Url","ThumbUrl","Enabled","Priority","DefaultImg","ImageIndex","SameImages"),
+ array($Name, $Alt, $ResourceId, $LocalImage, $LocalThumb,
+ $Url, $ThumbUrl, $Enabled, $Priority, $DefaultImg, $ImageIndex,$SameImages));
+
+ if((int)$ImageIndex==0)
+ $img->Set("ImageIndex",$this->GetNextImageIndex($ResourceId));
+
+ $img->Update();
+
+ if($DefaultImg==1)
+ {
+ $sql = "UPDATE ".$this->SourceTable." SET DefaultImg=0 WHERE ResourceId=".$ResourceId." AND ImageId !=$ImageId";
+ $this->adodbConnection->Execute($sql);
+ }
+ array_push($this->Items,$img);
+
+ return $img;
+ }
+
+ function Delete_Image($ImageId)
+ {
+ $i = $this->GetItem($ImageId);
+ $i->Delete();
+ }
+
+ function DeleteResource($ResourceId)
+ {
+ $this->Clear();
+ $images = $this->Query_Images("ResourceId=".$ResourceId);
+ if(is_array($images))
+ {
+ foreach($images as $i)
+ {
+ $i->Delete();
+ }
+ }
+ }
+
+ function LoadResource($ResourceId)
+ {
+ $sql = "SELECT * FROM ".$this->SourceTable." WHERE ResourceId=$ResourceId";
+ $this->Query_Item($sql);
+ }
+
+ function CopyResource($SourceId,$DestId)
+ {
+ global $pathtoroot;
+
+ $this->Clear();
+ $this->LoadResource($SourceId);
+ foreach($this->Items as $i)
+ {
+ if($i->Get("LocalThumb"))
+ {
+ $f = $pathtoroot.$i->Get("ThumbPath");
+ if(file_exists($f))
+ {
+ $p = pathinfo($f);
+ $dir = $p["dirname"];
+ $ext = $p["extension"];
+ $newfile = $dir."/th_".$DestId."_".$i->Get("ImageIndex").".".$ext;
+ if(file_exists($newfile))
+ @unlink($newfile);
+ // echo $f." -> ".$newfile;
+ copy($f,$newfile);
+ }
+ }
+ if($i->Get("LocalImage"))
+ {
+ $f = $pathtoroot.$i->Get("LocalPath");
+ if(file_exists($f))
+ {
+ $p = pathinfo($f);
+ $dir = $p["dirname"];
+ $ext = $p["extension"];
+ $newfile = $dir."/".$DestId."_".$i->Get("ImageIndex").".".$ext;
+ if(file_exists($newfile))
+ @unlink($newfile);
+
+ // echo $f." -> ".$newfile;
+ copy($f,$newfile);
+ }
+ }
+ }
+ parent::CopyResource($SourceId,$DestId);
+ $this->Clear();
+ $this->LoadResource($DestId);
+ foreach($this->Items as $img)
+ {
+ if($img->Get("LocalThumb"))
+ {
+ $f = str_replace("th_$SourceId","th_$DestId",$img->Get("ThumbPath"));
+ $img->Set("ThumbPath",$f);
+ }
+ if($img->Get("LocalImage"))
+ {
+ $f = str_replace("/".$SourceId."_","/".$DestId."_",$img->Get("LocalPath"));
+ $img->Set("LocalPath",$f);
+ }
+ $img->Update();
+ }
+ }
+
+ function GetImageByResource($ResourceId,$Index)
+ {
+ $found=FALSE;
+ if($this->NumItems()>0)
+ {
+ foreach($this->Items as $i)
+ {
+ if($i->Get("ResourceID")==$ResourceId and ($i->Get("ImageIndex")==$Index))
+ {
+ $found=TRUE;
+ break;
+ }
+ }
+ }
+ if(!$found)
+ {
+ $i = NULL;
+ $i = new clsImage();
+ if($i->LoadFromResource($ResourceId,$Index))
+ {
+ array_push($this->Items, $i);
+ }
+ else
+ unset($i);
+ }
+ if(is_object($i))
+ {
+ return $i;
+ }
+ else
+ return FALSE;
+ }
+
+ function &GetDefaultImage($ResourceId)
+ {
+ $sql = "SELECT * FROM ".$this->SourceTable." WHERE ResourceId=$ResourceId AND DefaultImg=1";
+ $rs = $this->adodbConnection->Execute($sql);
+ if($rs && ! $rs->EOF)
+ {
+ $data = $rs->fields;
+ $img= new clsImage();
+ $img->SetFromArray($data);
+ $img->Clean();
+ return $img;
+ }
+ else
+ return FALSE;
+
+ }
+ function HandleImageUpload($FILE,$ResourceId,$RelatedTo,$DestDir, $Name="",$AltName="",$IsThumb=0)
+ {
+ global $objConfig;
+
+ $img = $this->GetImageByResource($ResourceId,$RelatedTo);
+
+ if(is_object($img) && $RelatedTo>0)
+ {
+ $img->Set("LocalImage",1);
+ $img->Set("Name",$Name);
+ $img->Set("AltName",$AltName);
+ $img->Set("IsThumbnail",$IsThumb);
+ $dest = $img->StoreUploadedImage($FILE,1,$DestDir);
+ if(strlen($dest))
+ {
+ $img->Set("Url", $objConfig->Get("Site_Path").$dest);
+ $img->Update();
+ }
+ }
+ else
+ {
+ $img=$this->NewLocalImage($ResourceId,$RelatedTo,$Name,$AltName,$IsThumb,$FILE,$DestDir);
+ }
+ return $img;
+ }
+
+ function GetResourceImages($ResourceId)
+ {
+ $sql = "SELECT * FROM ".$this->SourceTable." WHERE ResourceId=".$ResourceId;
+ $rs = $this->adodbConnection->Execute($sql);
+ while($rs && !$rs->EOF)
+ {
+ $img = new clsImage();
+ $img->LoadFromResource($ResourceId,$rs->fields["RelatedTo"]);
+ array_push($this->Images,$img);
+ $rs->MoveNext();
+ }
+ }
+
+ function GetResourceThumbnail($ResourceId)
+ {
+ $found=FALSE;
+ foreach($this->Images as $img)
+ {
+ if($img->Get("ResourceId")==$ResourceId && $img->Get("IsThumbnail")==1)
+ {
+ $found=TRUE;
+ break;
+ }
+ }
+ if($found)
+ {
+ return $img;
+ }
+ else
+ return FALSE;
+ }
+
+ function &GetImageByName($ResourceId,$name)
+ {
+ $found = FALSE;
+ foreach($this->Items as $img)
+ {
+ if($img->Get("ResourceId")==$ResourceId && $img->Get("Name")==$name)
+ {
+ $found=TRUE;
+ break;
+ }
+ }
+ if($found)
+ {
+ return $img;
+ }
+ else
+ {
+ $sql = "SELECT * FROM ".$this->SourceTable." WHERE ResourceId=$ResourceId AND Name LIKE '$name'";
+ //echo $sql;
+ $rs = $this->adodbConnection->Execute($sql);
+ if($rs && !$rs->EOF)
+ {
+ $img = $this->AddItemFromArray($rs->fields);
+ return $img;
+ }
+ else
+ return FALSE;
+ }
+ }
+
+ function CopyToPendingFiles()
+ {
+ $sql = "SELECT * FROM ".$this->SourceTable;
+ $this->Clear();
+ $this->Query_Item($sql);
+ foreach($this->Items as $i)
+ {
+ if(strlen($i->Get("LocalImage")) || strlen($i->Get("LocalThumb")))
+ {
+ $i->CopyToPending();
+ }
+ }
+ }
+
+ function CopyFromPendingFiles($edit_table)
+ {
+ $sql = "SELECT * FROM ".$edit_table;
+ $this->Clear();
+ $this->Query_Item($sql);
+ foreach($this->Items as $i)
+ {
+
+ ## Delete original Images
+ $OrgImage = new clsImage($i->Get("ImageId"));
+ $OrgImage->DeleteLocalImage();
+
+ if($i->Get("LocalImage") || $i->Get("LocalThumb"))
+ {
+ $i->CopyFromPending();
+
+ $t = $i->Get("LocalPath");
+
+ $p = pathinfo($t);
+ $p_arr = explode("/", $p['dirname']);
+ if (eregi("pending", $p_arr[count($p_arr)-1]))
+ {
+ unset($p_arr[count($p_arr)-1]);
+ $p['dirname'] = implode("/", $p_arr);
+ $LocalPath = $p['dirname']."/".$p['basename'];
+ $i->Set("LocalPath", $LocalPath);
+ }
+
+ $t = $i->Get("ThumbPath");
+ $p = pathinfo($t);
+
+ $p_arr = explode("/", $p['dirname']);
+ if (eregi("pending", $p_arr[count($p_arr)-1]))
+ {
+ unset($p_arr[count($p_arr)-1]);
+ $p['dirname'] = implode("/", $p_arr);
+ $ThumbPath = $p['dirname']."/".$p['basename'];
+ $i->Set("ThumbPath", $ThumbPath);
+ }
+
+ $i->tablename = $edit_table;
+
+ $update = 1;
+ }
+
+ ## Empty the fields if are not used
+ if (!$i->Get("LocalImage"))
+ {
+ $i->Set("LocalPath", "");
+ $update = 1;
+ }
+
+ if (!$i->Get("LocalThumb"))
+ {
+ $i->Set("ThumbPath", "");
+ $update = 1;
+ }
+
+ if ($update)
+ $i->Update();
+
+ }
+ }
+
+ function DeletePendingFiles($edit_table)
+ {
+ $sql = "SELECT * FROM ".$edit_table;
+ $this->Clear();
+ $this->Query_Item($sql);
+ foreach($this->Items as $i)
+ {
+ $i->DeleteFromPending();
+ }
+ }
+
+ function CopyToEditTable($idfield, $idlist)
+ {
+ global $objSession;
+
+ $edit_table = $objSession->GetEditTable($this->SourceTable);
+ @$this->adodbConnection->Execute("DROP TABLE IF EXISTS $edit_table");
+ if(is_array($idlist))
+ {
+ $list = implode(",",$idlist);
+ }
+ else
+ $list = $idlist;
+ $query = "SELECT * FROM ".$this->SourceTable." WHERE $idfield IN ($list)";
+ $insert = "CREATE TABLE ".$edit_table." ".$query;
+ if($objSession->HasSystemPermission("DEBUG.LIST"))
+ echo htmlentities($insert,ENT_NOQUOTES)."<br>\n";
+ $this->adodbConnection->Execute($insert);
+ $this->SourceTable = $edit_table;
+ $this->CopyToPendingFiles();
+
+ $this->UpdateFilenamesToPendings();
+ }
+
+ function UpdateFilenamesToPendings()
+ {
+ global $objSession;
+
+ $edit_table = $this->SourceTable;
+
+ $sql = "SELECT * FROM ".$edit_table." WHERE (LocalPath!='' AND LocalPath IS NOT NULL) OR (ThumbPath!='' AND ThumbPath IS NOT NULL)";
+ $this->Clear();
+ $this->Query_Item($sql);
+
+ foreach($this->Items as $i)
+ {
+ $set = "";
+ $ImageId = $i->Get("ImageId");
+
+ ## Update Local Image Path -> add "pending/" to PATH
+ if (strlen($i->Get("LocalPath")))
+ {
+ $p = pathinfo($i->Get("LocalPath"));
+ if (!eregi("/pending $", $p['dirname']))
+ {
+ $LocalPath = $p['dirname']."/pending/".$p['basename'];
+ $set = "SET LocalPath='$LocalPath'";
+ }
+ }
+
+ // echo "LocalImage: ".$i->Get("LocalImage").", PATH: ".$i->Get("LocalPath")."<BR>";
+
+ ## Update Local Thumb Path -> add "pending/" to PATH
+ if (strlen($i->Get("ThumbPath")))
+ {
+ $p = pathinfo($i->Get("ThumbPath"));
+ if (!eregi("/pending $", $p['dirname']))
+ {
+ $LocalThumb = $p['dirname']."/pending/".$p['basename'];
+ if (strlen($set))
+ $set.= ", ThumbPath='$LocalThumb'";
+ else
+ $set = "SET ThumbPath='$LocalThumb'";
+ }
+ }
+
+ // echo "LocalThumb: ".$i->Get("LocalThumb").", PATH: ".$i->Get("ThumbPath")."<BR>";
+
+ if (strlen($set))
+ {
+ $sql = "UPDATE $edit_table $set WHERE ImageId=$ImageId";
+ if($objSession->HasSystemPermission("DEBUG.LIST"))
+ echo htmlentities($sql,ENT_NOQUOTES)."<br>\n";
+ $this->adodbConnection->Execute($sql);
+ }
+ }
+ }
+
+ function CopyFromEditTable($idfield)
+ {
+ global $objSession;
$GLOBALS['_CopyFromEditTable']=1;
-
- $edit_table = $objSession->GetEditTable($this->SourceTable);
- $dummy =& $this->GetDummy();
- if( !$dummy->TableExists($edit_table) )
- {
- echo 'ERROR: Table "<b>'.$edit_table.'</b>" missing (class: <b>'.get_class($this).'</b>)<br>';
- //exit;
- return;
- }
-
- $rs = $this->adodbConnection->Execute("SELECT * FROM $edit_table WHERE ResourceId=0");
- while($rs && !$rs->EOF)
- {
- $id = $rs->fields["ImageId"];
- if($id>0)
- {
- $img = $this->GetItem($id);
- $img->Delete();
- }
- $rs->MoveNext();
- }
- $this->adodbConnection->Execute("DELETE FROM $edit_table WHERE ResourceId=0");
- $this->CopyFromPendingFiles($edit_table);
- parent::CopyFromEditTable($idfield);
+
+ $edit_table = $objSession->GetEditTable($this->SourceTable);
+ $dummy =& $this->GetDummy();
+ if( !$dummy->TableExists($edit_table) )
+ {
+ echo 'ERROR: Table "<b>'.$edit_table.'</b>" missing (class: <b>'.get_class($this).'</b>)<br>';
+ //exit;
+ return;
+ }
+
+ $rs = $this->adodbConnection->Execute("SELECT * FROM $edit_table WHERE ResourceId=0");
+ while($rs && !$rs->EOF)
+ {
+ $id = $rs->fields["ImageId"];
+ if($id>0)
+ {
+ $img = $this->GetItem($id);
+ $img->Delete();
+ }
+ $rs->MoveNext();
+ }
+ $this->adodbConnection->Execute("DELETE FROM $edit_table WHERE ResourceId=0");
+ $this->CopyFromPendingFiles($edit_table);
+ parent::CopyFromEditTable($idfield);
unset($GLOBALS['_CopyFromEditTable']);
- }
-
- function PurgeEditTable($idfield)
- {
- global $objSession;
-
- $edit_table = $objSession->GetEditTable($this->SourceTable);
- $this->DeletePendingFiles($edit_table);
- @$this->adodbConnection->Execute("DROP TABLE IF EXISTS $edit_table");
- }
-
- function GetNextImageIndex($ResourceId)
- {
- $sql = "SELECT MAX(ImageIndex) as MaxVal FROM ".$this->SourceTable." WHERE ResourceId=".$ResourceId;
- $rs = $this->adodbConnection->Execute($sql);
- if($rs)
- {
- $val = (int)$rs->fields["MaxVal"];
- $val++;
- }
- return $val;
- }
-
- function GetMaxPriority($ResourceId)
- {
- $sql = "SELECT MAX(Priority) as p from ".$this->SourceTable."WHERE ResourceId=$ResourceId";
- $result = $this->adodbConnection->Execute($sql);
- return $result->fields["p"];
- }
-
- function GetMinPriority($ResourceId)
- {
- $sql = "SELECT MIN(Priority) as p from ".$this->SourceTable."WHERE ResourceId=$ResourceId";
- $result = $this->adodbConnection->Execute($sql);
- return $result->fields["p"];
- }
+ }
+
+ function PurgeEditTable($idfield)
+ {
+ global $objSession;
+
+ $edit_table = $objSession->GetEditTable($this->SourceTable);
+ $this->DeletePendingFiles($edit_table);
+ @$this->adodbConnection->Execute("DROP TABLE IF EXISTS $edit_table");
+ }
+
+ function GetNextImageIndex($ResourceId)
+ {
+ $sql = "SELECT MAX(ImageIndex) as MaxVal FROM ".$this->SourceTable." WHERE ResourceId=".$ResourceId;
+ $rs = $this->adodbConnection->Execute($sql);
+ if($rs)
+ {
+ $val = (int)$rs->fields["MaxVal"];
+ $val++;
+ }
+ return $val;
+ }
+
+ function GetMaxPriority($ResourceId)
+ {
+ $sql = "SELECT MAX(Priority) as p from ".$this->SourceTable."WHERE ResourceId=$ResourceId";
+ $result = $this->adodbConnection->Execute($sql);
+ return $result->fields["p"];
+ }
+
+ function GetMinPriority($ResourceId)
+ {
+ $sql = "SELECT MIN(Priority) as p from ".$this->SourceTable."WHERE ResourceId=$ResourceId";
+ $result = $this->adodbConnection->Execute($sql);
+ return $result->fields["p"];
+ }
} /*clsImageList*/
?>
Property changes on: trunk/kernel/include/image.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.11
\ No newline at end of property
+1.12
\ No newline at end of property

Event Timeline