Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Sun, Feb 2, 6:45 AM

in-portal

Index: trunk/kernel/action.php
===================================================================
--- trunk/kernel/action.php (revision 911)
+++ trunk/kernel/action.php (revision 912)
@@ -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"]);
+ $_POST["decimal"],$_POST["thousand"],$_POST['charset']);
$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->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");
}
$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.63
\ No newline at end of property
+1.64
\ No newline at end of property
Index: trunk/kernel/include/db.class.php
===================================================================
--- trunk/kernel/include/db.class.php (nonexistent)
+++ trunk/kernel/include/db.class.php (revision 912)
@@ -0,0 +1,400 @@
+<?php
+
+ /**
+ * Multi database connection class
+ *
+ */
+ class DBConnection {
+
+ /**
+ * Current database type
+ *
+ * @var string
+ * @access private
+ */
+ var $dbType = 'mysql';
+ /**
+ * Created connection handle
+ *
+ * @var resource
+ * @access private
+ */
+ var $connectionID = null;
+ /**
+ * Handle of currenty processed recordset
+ *
+ * @var resource
+ * @access private
+ */
+ var $queryID = null;
+ /**
+ * DB type specific function mappings
+ *
+ * @var Array
+ * @access private
+ */
+ var $metaFunctions = Array();
+
+ /**
+ * Function to handle sql errors
+ *
+ * @var string
+ * @access private
+ */
+ var $errorHandler = '';
+
+ /**
+ * Error code
+ *
+ * @var int
+ * @access private
+ */
+ var $errorCode = 0;
+ /**
+ * Error message
+ *
+ * @var string
+ * @access private
+ */
+ var $errorMessage = '';
+
+ /**
+ * Initializes connection class with
+ * db type to used in future
+ *
+ * @param string $dbType
+ * @return DBConnection
+ * @access public
+ */
+ function DBConnection($dbType, $errorHandler = '')
+ {
+ $this->dbType = $dbType;
+ $this->initMetaFunctions();
+ if(!$errorHandler)
+ {
+ $this->errorHandler = Array(&$this,'handleError');
+ }
+ }
+
+ /**
+ * Set's custom error
+ *
+ * @param int $code
+ * @param string $msg
+ * @access public
+ */
+ function setError($code,$msg)
+ {
+ $this->errorCode=$code;
+ $this->errorMessage=$msg;
+ }
+
+ /**
+ * Checks if previous query execution
+ * raised an error.
+ *
+ * @return bool
+ * @access public
+ */
+ function hasError()
+ {
+ return !($this->errorCode == 0);
+ }
+
+ /**
+ * Caches function specific to requested
+ * db type
+ *
+ * @access private
+ */
+ function initMetaFunctions()
+ {
+ $ret = Array();
+ switch($this->dbType)
+ {
+ case 'mysql':
+ $ret = Array(); // only define functions, that name differs from "dbType_<meta_name>"
+
+ break;
+
+
+ }
+ $this->metaFunctions = $ret;
+ }
+
+ /**
+ * Get's function for specific db type
+ * based on it's meta name
+ *
+ * @param string $name
+ * @return string
+ * @access private
+ */
+ function getMetaFunction($name)
+ {
+ if( !isset($this->metaFunctions[$name]) )
+ {
+ if(function_exists($this->dbType.'_'.$name)) return $this->dbType.'_'.$name;
+ }
+ else
+ {
+ return $this->dbType.$name;
+ }
+ return false;
+ }
+
+
+ /**
+ * Try to connect to database server
+ * using specified parameters and set
+ * database to $db if connection made
+ *
+ * @param string $host
+ * @param string $user
+ * @param string $pass
+ * @param string $db
+ * @access public
+ */
+ function Connect($host,$user,$pass,$db)
+ {
+ $func = $this->getMetaFunction('connect');
+ $this->connectionID = $func($host,$user,$pass) or die('Can\'t connect to db');
+ if($this->connectionID)
+ {
+ $this->setDB($db);
+ $this->showError();
+ }
+ }
+
+ /**
+ * Shows error message from previous operation
+ * if it failed
+ *
+ * @access private
+ */
+ function showError($sql='')
+ {
+ $this->setError(0,''); // reset error
+ if($this->connectionID)
+ {
+ $func = $this->getMetaFunction('errno'); $this->errorCode = $func($this->connectionID);
+ if($this->hasError())
+ {
+ $func = $this->getMetaFunction('error'); $this->errorMessage = $func($this->connectionID);
+ if(is_array($this->errorHandler))
+ {
+ $func = $this->errorHandler[1];
+ $ret = $this->errorHandler[0]->$func($this->errorCode,$this->errorMessage,$sql);
+ }
+ else
+ {
+ $func = $this->errorHandler;
+ $ret = $func($this->errorCode,$this->errorMessage,$sql);
+ }
+ if(!$ret) exit;
+ }
+ }
+ }
+
+ /**
+ * Default error handler for sql errors
+ *
+ * @param int $code
+ * @param string $msg
+ * @param string $sql
+ * @return bool
+ * @access private
+ */
+ function handleError($code,$msg,$sql)
+ {
+ echo '<b>Processing SQL</b>: '.$sql.'<br>';
+ echo '<b>Error ('.$code.'):</b> '.$msg.'<br>';
+ return false;
+ }
+
+ /**
+ * Set's database name for connection
+ * to $new_name
+ *
+ * @param string $new_name
+ * @return bool
+ * @access public
+ */
+ function setDB($new_name)
+ {
+ if(!$this->connectionID) return false;
+ $func = $this->getMetaFunction('select_db');
+ return $func($new_name);
+ }
+
+ /**
+ * Returns first field of first line
+ * of recordset if query ok or false
+ * otherwise
+ *
+ * @param string $sql
+ * @return string
+ * @access public
+ */
+ function GetOne($sql)
+ {
+ $row = $this->GetRow($sql);
+ if(!$row) return false;
+
+ return array_shift($row);
+ }
+
+ /**
+ * Returns first row of recordset
+ * if query ok, false otherwise
+ *
+ * @param stirng $sql
+ * @return Array
+ * @access public
+ */
+ function GetRow($sql)
+ {
+ $sql .= ' '.$this->getLimitClause(0,1);
+ $ret = $this->Query($sql);
+ if(!$ret) return $ret;
+
+ return array_shift($ret);
+ }
+
+ /**
+ * Returns 1st column of recordset as
+ * one-dimensional array or false otherwise
+ * Optional parameter $key_field can be used
+ * to set field name to be used as resulting
+ * array key
+ *
+ * @param string $sql
+ * @param string $key_field
+ * @return Array
+ * @access public
+ */
+ function GetCol($sql, $key_field = null)
+ {
+ $rows = $this->Query($sql);
+ if(!$rows) return $rows;
+
+ $i = 0; $row_count = count($rows);
+ $ret = Array();
+ if(isset($key_field))
+ {
+ while ($i < $row_count)
+ {
+ $ret[$rows[$i][$key_field]] = array_shift($rows[$i]);
+ $i++;
+ }
+ }
+ else
+ {
+ while ($i < $row_count)
+ {
+ $ret[] = array_shift($rows[$i]);
+ $i++;
+ }
+ }
+ return $ret;
+ }
+
+ /**
+ * Queries db with $sql query supplied
+ * and returns rows selected if any, false
+ * otherwise. Optional parameter $key_field
+ * allows to set one of the query fields
+ * value as key in string array.
+ *
+ * @param string $sql
+ * @param string $key_field
+ * @return Array
+ */
+ function Query($sql, $key_field = null)
+ {
+ $query_func = $this->getMetaFunction('query');
+ $this->queryID = $query_func($sql,$this->connectionID);
+ if( is_resource($this->queryID) )
+ {
+ $ret = Array();
+ $fetch_func = $this->getMetaFunction('fetch_assoc');
+ if( isset($key_field) )
+ {
+ while( ($row = $fetch_func($this->queryID)) )
+ {
+ $ret[$row[$key_field]] = $row;
+ }
+ }
+ else
+ {
+ while( ($row = $fetch_func($this->queryID)) )
+ {
+ $ret[] = $row;
+ }
+ }
+ $this->Destroy();
+ return $ret;
+ }
+ $this->showError($sql);
+ return false;
+ }
+
+ /**
+ * Free memory used to hold recordset handle
+ *
+ * @access private
+ */
+ function Destroy()
+ {
+ if($this->queryID)
+ {
+ $free_func = $this->getMetaFunction('free_result');
+ $free_func($this->queryID);
+ $this->queryID = null;
+ }
+ }
+
+ /**
+ * Returns auto increment field value from
+ * insert like operation if any, zero otherwise
+ *
+ * @return int
+ * @access public
+ */
+ function getInsertID()
+ {
+ $func = $this->getMetaFunction('insert_id');
+ return $func($this->connectionID);
+ }
+
+ /**
+ * Returns row count affected by last query
+ *
+ * @return int
+ * @access public
+ */
+ function getAffectedRows()
+ {
+ $func = $this->getMetaFunction('affected_rows');
+ return $func($this->connectionID);
+ }
+
+ /**
+ * Returns LIMIT sql clause part for specific db
+ *
+ * @param int $offset
+ * @param int $rows
+ * @return string
+ * @access private
+ */
+ function getLimitClause($offset, $rows)
+ {
+ switch ($this->dbType) {
+
+ default:
+ return 'LIMIT '.$offset.','.$rows;
+ break;
+ }
+ }
+ }
+?>
\ No newline at end of file
Property changes on: trunk/kernel/include/db.class.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.1
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/kernel/include/config.php
===================================================================
--- trunk/kernel/include/config.php (revision 911)
+++ trunk/kernel/include/config.php (revision 912)
@@ -1,513 +1,514 @@
<?php
+require_once($pathtoroot."kernel/include/db.class.php");
require_once($pathtoroot."kernel/include/adodb/adodb.inc.php");
class clsConfig
{
var $config;
var $m_dirty_session;
var $m_IsDirty;
var $m_DirtyFields;
var $m_VarType;
var $adodbConnection;
function clsConfig()
{
$this->m_IsDirty=false;
$this->adodbConnection = &GetADODBConnection();
$this->config = array();
$this->m_IsDefault = array();
$this->VarType = array();
}
function SetDebugLevel($value)
{
}
function Load()
{
if(is_object($this->adodbConnection))
{
LogEntry("Config Load Start\n");
$sql = "select VariableName, VariableValue from ".GetTablePrefix()."ConfigurationValues";
$rs = $this->adodbConnection->Execute($sql);
unset($this->config);
#this->config=array();
$count=0;
while($rs && !$rs->EOF)
{
$this->config[$rs->fields["VariableName"]] = $rs->fields["VariableValue"];
$this->m_VarType[$rs->fields["VariableName"]] = 0;
// $this->Set($rs->fields["VariableName"],$rs->fields["VariableValue"],0);
if( defined('ADODB_EXTENSION') && constant('ADODB_EXTENSION') > 0 )
{
adodb_movenext($rs);
}
else
$rs->MoveNext();
$count++;
}
LogEntry("Config Load End - $count Variables\n");
}
unset($this->m_DirtyFields);
$this->m_IsDirty=false;
}
function Get($property)
{
return isset($this->config[$property]) ? $this->config[$property] : '';
}
function Set($property, $value,$type=0,$force=FALSE)
{
if(is_array($this->config) && strlen($property)>0)
{
if(array_key_exists($property,$this->config))
{
$current = $this->config[$property];
$changed = ($current != $value);
}
else
$changed = true;
}
else
$changed = false;
$this->config[$property]=$value;
$this->m_IsDirty = ($this->m_IsDirty or $changed or $force);
if($changed || $force)
{
$this->m_DirtyFields[$property] = $value;
}
$this->m_VarType[$property] = $type;
}
function Save()
{
if($this->m_IsDirty==TRUE)
{
foreach($this->m_DirtyFields as $field=>$value)
{
if($this->m_VarType[$field]==0)
{
// $sql = sprintf("UPDATE ".GetTablePrefix()."ConfigurationValues SET VariableValue=%s WHERE VariableName=%s", $this->adodbConnection->qstr($value), $this->adodbConnection->qstr($field));
$sql = 'UPDATE '.GetTablePrefix().'ConfigurationValues SET VariableValue="'.addslashes($value).'" WHERE VariableName="'.addslashes($field).'"';
// echo $sql."<br>\n";
$rs = $this->adodbConnection->execute($sql);
}
}
}
$this->m_IsDirty=FALSE;
unset($this->m_DirtyFields);
}
function TimeFormat()
{
if($this->Get("ampm_time")=="1")
{
$format = "g:i:s A";
}
else
$format = "H:i:s";
return $format;
}
/* vartype should be either 1 or 2, 1 = perstant data, 2 = session data */
function GetDirtySessionValues($VarType)
{
$result = array();
if(is_array($this->m_DirtyFields))
{
foreach($this->m_DirtyFields as $property=>$values)
{
if($this->m_VarType[$property]==$VarType)
$result[$property] = $values;
}
}
return $result;
}
function GetConfigValues($postfix = '')
{
// return only varibles, that match specified criteria
if(!$postfix) return $this->config;
$result = Array();
$postfix_len = $postfix ? strlen($postfix) : 0;
foreach($this->config as $config_var => $var_value)
{
if( substr($config_var, - $postfix_len) == $postfix )
$result[$config_var] = $var_value;
}
return $result;
}
}/* clsConfig */
/*
To create the configuration forms in the admin section, populate the table ConfigurationAdmin and
ConfigurationValues.
The tables are fairly straight-forward. The fields of concern in the ConfigurationValues table is
ModuleOwner and Section. ModuleOwner should either be the module name or In-Portal for kernel related stuff.
(Items which should appear under 'System Configuration').
The Section field determines the NavMenu section the value is associated with. For example,
in-portal:configure_general refers to items listed under System Configuration->General.
In the ConfigurationAdmin table, ensure the VariableName field is the same as the one in ConfigurationValues
(this is the field that creates the natural join.) The prompt field is the text displayed to the left of the form element
in the table. This should contain LANGUAGE ELEMENT IDENTIFIERS that are plugged into the Language function.
The element_type field describes the type of form element is associated with this item. Possible values are:
- text : textbox
- checkbox : a simple checkbox
- select : creates a dropdown box. In this case, the ValueList field should be populated with a comma-separated list
in name=value,name=value format (each element is translated to:
<option VALUE="[value]">[name]</option>
To add dynamic data to this list, enclose an SQL statement with <SQL></SQL> tags for example:
<SQL>SELECT FieldLabel as OptionName, FieldName as OptionValue FROM <prefix>CustomField WHERE <prefix>.CustomFieldType=3></SQL>
note the specific field labels OptionName and OptionValue. They are required by the parser.
use the <prefix> tag to insert the system's table prefix into the sql statement as appropriate
*/
class clsConfigAdminItem
{
var $name;
var $heading;
var $prompt;
var $ElementType;
var $ValueList; /* comma-separated list in name=value pair format*/
var $ValidationRules;
var $default_value;
var $adodbConnection;
var $NextItem=NULL;
var $Section;
function clsConfigAdminItem($config_name=NULL)
{
$this->adodbConnection = &GetADODBConnection();
if($config_name)
$this->LoadSetting($config_name);
}
function LoadSetting($config_name)
{
$sql = "SELECT * FROM ".GetTablePrefix()."ConfigurationAdmin INNER JOIN ".GetTablePrefix()."ConfigurationValues Using(VariableName) WHERE ".GetTablePrefix()."ConfigurationAdmin.VariableName='".$config_name."'";
$rs = $this->adodbConnection->Execute($sql);
if($rs && !$rs->EOF)
{
$this->name = $rs->fields["VariableName"];
$this->heading = $rs->fields["heading"];
$this->prompt = $rs->fields["prompt"];
$this->ElementType = $rs->fields["element_type"];
$this->ValidationRules=$rs->fields["validation"];
$this->default_value = $rs->fields["VariableValue"];
$this->ValueList=$rs->fields["ValueList"];
$this->Section = $rs->fields["Section"];
}
}
function explode_sql($sql)
{
$s = "";
$rs = $this->adodbConnection->Execute($sql);
while ($rs && !$rs->EOF)
{
if(strlen(trim($rs->fields["OptionName"]))>0 && strlen(trim($rs->fields["OptionValue"]))>0)
{
if(strlen($s))
$s .= ",";
$s .= $rs->fields["OptionName"]."="."+".$rs->fields["OptionValue"];
}
$rs->MoveNext();
}
return $s;
}
function replace_sql($string)
{
$string = str_replace("<PREFIX>",GetTablePrefix(),$string);
$start = strpos($string,"<SQL>");
while($start)
{
$end = strpos($string,"</SQL>");
if(!$end)
{
$end = strlen($string);
}
$len = $end - $start;
$sql = substr($string,$start+5,$len-5);
$sql_val = $this->explode_sql($sql);
$s = substr($string,0,$start) . $sql_val . substr($string,$end+5);
$string = $s;
$start = strpos($string,"<SQL>");
}
return $string;
}
function ItemFormElement($StartFrom=1)
{
global $objConfig;
static $TabIndex;
if (empty($TabIndex))
$TabIndex = $StartFrom;
$o = "";
if($objConfig->Get($this->name)!="")
$this->default_value = $objConfig->Get($this->name);
$this->default_value=inp_htmlize($this->default_value);
switch($this->ElementType)
{
case "text":
$o .= "<INPUT TYPE=\"TEXT\" tabindex=\"".($TabIndex++)."\" NAME=\"".$this->name."\" ";
$o .= "VALUE=\"".$this->default_value."\">";
break;
case "checkbox":
$o .= "<INPUT TYPE=\"checkbox\" NAME=\"".$this->name."\" tabindex=\"".($TabIndex++)."\"";
if($this->default_value)
{
$o .= " CHECKED>";
}
else
$o .= ">";
break;
case "password":
/* To exclude config form from populating with Root (md5) password */
if ($this->Section == "in-portal:configure_users")
$this->default_value = "";
$o .= "<INPUT TYPE=\"PASSWORD\" tabindex=\"".($TabIndex++)."\" NAME=\"".$this->name."\" ";
$o .= "VALUE=\"".$this->default_value."\">";
break;
case "textarea":
$o .= "<TEXTAREA tabindex=\"".($TabIndex++)."\" ".$this->ValueList." name=\"".$this->name."\">".$this->default_value."</TEXTAREA>";
break;
case "label":
if($this->default_value)
{
$o .= $this->default_value;
}
break;
case "radio":
$radioname = $this->name;
$ValList = $this->replace_sql($this->ValueList);
$TabIndex++;
$localTabIndex = $TabIndex;
$TabIndex++;
$val = explode(",",$ValList);
for($i=0;$i<=count($val);$i++)
{
if(strlen($val[$i]))
{
$parts = explode("=",$val[$i]);
$s = $parts[1];
if(strlen($s)==0)
$s="";
$o .= "<input type=\"radio\" tabindex=\"".($localTabIndex)."\" name=\"".$this->name."\" VALUE=\"".$parts[0]."\"";
if($this->default_value==$parts[0])
{
$o .= " CHECKED>";
}
else
$o .= ">";
if(substr($s,0,1)=="+")
{
$o .= $s;
}
else
$o .= prompt_language($s);
}
}
break;
case "select":
$o .= "<SELECT NAME=\"".$this->name."\" tabindex=\"".($TabIndex++)."\">";
$ValList = $this->replace_sql($this->ValueList);
$val = explode(",",$ValList);
for($i=0;$i<=count($val);$i++)
{
if(strlen($val[$i]))
{
$parts = explode("=",$val[$i]);
$s = $parts[1];
if(strlen($s)==0)
$s="";
$selected = "";
if($this->default_value==$parts[0])
$selected = " SELECTED";
if(substr($s,0,1)=="+")
{
$o .= "<OPTION VALUE=\"".$parts[0]."\" $selected>".substr($s,1)."</OPTION>";
}
else
{
if(strlen($s))
$o .= "<OPTION VALUE=\"".$parts[0]."\" $selected>".admin_language($s)."</OPTION>";
}
}
}
$o .= "</SELECT>";
}
return $o;
}
function GetPrompt()
{
$ret = prompt_language($this->prompt);
return $ret;
}
}
class clsConfigAdmin
{
var $module;
var $section;
var $Items;
function clsConfigAdmin($module="",$section="",$Inst=FALSE)
{
$this->module = $module;
$this->section = $section;
$this->Items= array();
if(strlen($module) && strlen($section))
$this->LoadItems(TRUE,$Inst);
}
function Clear()
{
unset($this->Items);
$this->Items = array();
}
function NumItems()
{
if(is_array($this->Items))
{
return count($this->Items);
}
else
return 0;
}
function LoadItems($CheckNextItems=TRUE, $inst=FALSE)
{
$this->Clear();
if(!$inst)
{
$sql = "SELECT * FROM ".GetTablePrefix()."ConfigurationAdmin INNER JOIN ".GetTablePrefix()."ConfigurationValues Using(VariableName)
WHERE ModuleOwner='".$this->module."' AND Section='".$this->section."' ORDER BY DisplayOrder ASC";
}
else
{
$sql = "SELECT * FROM ".GetTablePrefix()."ConfigurationAdmin INNER JOIN ".GetTablePrefix()."ConfigurationValues Using(VariableName)
WHERE ModuleOwner='".$this->module."' AND Section='".$this->section."' AND Install=1 ORDER BY DisplayOrder ASC";
}
if( $GLOBALS['debuglevel'] ) echo $sql."<br>\n";
$adodbConnection = &GetADODBConnection();
$rs = $adodbConnection->Execute($sql);
while($rs && !$rs->EOF)
{
$data = $rs->fields;
if(is_object($i) && $CheckNextItems)
{
$last = $i->prompt;
unset($i);
}
$i = new clsConfigAdminItem(NULL);
$i->name = $data["VariableName"];
$i->default_value = $data["VariableValue"];
$i->heading = $data["heading"];
$i->prompt = $data["prompt"];
$i->ElementType = $data["element_type"];
$i->ValueList = $data["ValueList"];
$i->ValidationRules = isset($data['validaton']) ? $data['validaton'] : '';
$i->Section = $data["Section"];
if(strlen($last)>0)
{
if($i->prompt==$last)
{
$this->Items[count($this->Items)-1]->NextItem=$i;
}
else
{
$i->NextItem=NULL;
array_push($this->Items,$i);
}
}
else
{
$i->NextItem=NULL;
array_push($this->Items,$i);
}
//unset($i);
$rs->MoveNext();
}
}
function SaveItems($POSTVARS, $force=FALSE)
{
global $objConfig;
foreach($this->Items as $i)
{
if($i->ElementType != "label")
{
if($i->ElementType != "checkbox")
{
$objConfig->Set($i->name,stripslashes($POSTVARS[$i->name]));
}
else
{
if($POSTVARS[$i->name]=="on")
{
$value=1;
}
else
$value = (int)$POSTVARS[$i->name];
$objConfig->Set($i->name,stripslashes($value),0,$force);
}
}
}
$objConfig->Save();
}
function GetHeadingList()
{
$res = array();
foreach($this->Items as $i)
{
$res[$i->heading]=1;
}
reset($res);
return array_keys($res);
}
function GetHeadingItems($heading)
{
$res = array();
foreach($this->Items as $i)
{
if($i->heading==$heading)
array_push($res,$i);
}
return $res;
}
}
?>
\ No newline at end of file
Property changes on: trunk/kernel/include/config.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.11
\ No newline at end of property
+1.12
\ No newline at end of property
Index: trunk/kernel/include/language.php
===================================================================
--- trunk/kernel/include/language.php (revision 911)
+++ trunk/kernel/include/language.php (revision 912)
@@ -1,758 +1,758 @@
<?php
class clsPhrase extends clsItemDB
{
function clsPhrase($id=NULL)
{
$this->clsItemDB();
$this->tablename = GetTablePrefix()."Phrase";
$this->id_field = "PhraseId";
$this->NoResourceId=1;
if($id)
$this->LoadFromDatabase($id);
}
function LoadFromDatabase($Id)
{
global $Errors;
if(!isset($Id))
{
$Errors->AddError("error.AppError",NULL,'Internal error: LoadFromDatabase id',"",get_class($this),"LoadFromDatabase");
return false;
}
if($Id)
{
$sql = sprintf("SELECT * FROM ".$this->tablename." WHERE ".$this->IdField()." = '%s'",$Id);
$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;
$this->SetFromArray($data);
$this->Clean();
return true;
}
else
return FALSE;
}
function AdminIcon()
{
global $imagesURL;
return $imagesURL."/itemicons/icon16_language_var.gif";
}
}
class clsPhraseList extends clsItemCollection
{
var $Page;
var $PerPageVar;
function clsPhraseList()
{
$this->clsItemCollection();
$this->SourceTable = GetTablePrefix()."Phrase";
$this->classname = "clsPhrase";
$this->PerPageVar = "Perpage_Phrase";
$this->AdminSearchFields = array("p.Phrase","p.Translation");
}
function &AddPhrase($Phrase,$LangId,$Translation,$Type)
{
$tmpphrase = $this->GetPhrase($Phrase, $LangId);
if (!$tmpphrase) {
$p = new clsPhrase();
$p->tablename = $this->SourceTable;
$p->Set(array("Phrase","LanguageId","Translation","PhraseType"),
array($Phrase,$LangId,$Translation,$Type));
$p->Dirty();
$p->Create();
return $p;
}
else {
//echo 'phrase already exists with label <b>'.$Phrase.'</b><br>';
$add_error = "Error";
return $add_error;
/* $tmpphrase->Set(array("Phrase","LanguageId","Translation","PhraseType"),
array($Phrase,$LangId,$Translation,$Type));
$tmpphrase->Dirty();
$tmpphrase->Update();
return $tmpphrase;*/
}
}
function &EditPhrase($id,$Phrase,$LangId,$Translation,$Type)
{
$p = $this->GetItem($id);
$p->Set(array("Phrase","LanguageId","Translation","PhraseType"),
array($Phrase,$LangId,$Translation,$Type));
$p->Dirty();
$p->Update();
return $p;
}
function DeletePhrase($id)
{
$p = $this->GetItem($id);
$p->Delete();
}
function DeleteLanguage($LangId)
{
$sql = "DELETE FROM ".$this->SourceTable." WHERE LanguageId=$LangId";
if( $GLOBALS['debuglevel'] ) echo $sql."<br>\n";
$this->adodbConnection->Execute($sql);
}
function CopyFromEditTable()
{
global $objSession;
$GLOBALS['_CopyFromEditTable']=1;
$edit_table = $objSession->GetEditTable($this->SourceTable);
$sql='REPLACE '.GetTablePrefix().'Phrase SELECT * FROM '.$objSession->GetEditTable('Phrase').' WHERE PhraseId > 0';
$this->adodbConnection->Execute($sql);
$sql='INSERT INTO '.GetTablePrefix().'Phrase SELECT Phrase, Translation, PhraseType, 0, LanguageId FROM '.$objSession->GetEditTable('Phrase').' WHERE PhraseId < 0';
$this->adodbConnection->Execute($sql);
return;
//$idlist = array();
$sql = "SELECT * FROM $edit_table";
//echo "performing mass create/update<br>";
flush();
$this->Clear();
$rs = $this->adodbConnection->Execute($sql);
while($rs && !$rs->EOF)
{
$data = $rs->fields;
$c = $this->AddItemFromArray($data);
$c->Dirty();
if($data["PhraseId"]>0)
{
$c->Update();
}
else
{
$c->debuglevel=0;
$c->UnsetIdField();
$c->Create();
}
$rs->MoveNext();
}
// Phrases deleted from temporary table are marked with LanguageId = 0, when saving we need to actually delete them all
// The idea was taken from Images edit by Kostja
$sql = "DELETE FROM ".$this->SourceTable." WHERE LanguageId = 0";
$this->adodbConnection->Execute($sql);
if( $GLOBALS['debuglevel'] ) echo $sql."<br>\n";
$this->adodbConnection->Execute($sql);
unset($GLOBALS['_CopyFromEditTable']);
}
function PurgeEditTable()
{
global $objSession;
$edit_table = $objSession->GetEditTable($this->SourceTable);
$this->adodbConnection->Execute("DROP TABLE IF EXISTS $edit_table");
}
function GetPhrase($Phrase,$Lang, $no_db=FALSE)
{
$found = FALSE;
foreach($this->Items as $i)
{
if($i->Get("Phrase")==$Phrase && $i->Get("LanguageId")==$Lang)
{
$found = TRUE;
break;
}
}
if(!$found && !$no_db)
{
$sql = "SELECT * FROM ".$this->SourceTable." WHERE Phrase='$Phrase' AND LanguageId='$Lang'";
//echo $sql."<br>\n";
$rs = $this->adodbConnection->Execute($sql);
if($rs && !$rs->EOF)
{
$data = $rs->fields;
$i = $this->AddItemFromArray($data);
}
else
$i = FALSE;
}
return $i;
}
}
RegisterPrefix("clsLanguage","lang","kernel/include/language.php");
class clsLanguage extends clsParsedItem
{
function clsLanguage($id=NULL)
{
$this->clsParsedItem();
$this->tablename = GetTablePrefix()."Language";
$this->id_field = "LanguageId";
$this->NoResourceId=1;
$this->TagPrefix="lang";
if($id)
$this->LoadFromDatabase($id);
}
function LoadFromDatabase($Id)
{
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 ".$this->IdField()." = '%s'",$Id);
$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;
$this->SetFromArray($data);
$this->Clean();
return true;
}
function Delete()
{
$p = new clsPhraseList();
//$id = $this->Get("LanguageId");
//$p->DeleteLanguage($id);
parent::Delete();
}
function ParseObject($element)
{
global $m_var_list,$m_var_list_update, $var_list,$var_list_update, $TemplateRoot;
//echo "<PRE>"; print_r($element); echo "</PRE>";
$extra_attribs = ExtraAttributes($element->attributes);
if(strtolower($element->name)==$this->TagPrefix)
{
$field = strtolower($element->attributes["_field"]);
switch($field)
{
case "id":
$ret = $this->Get("LanguageId");
break;
case "packname":
$ret = $this->Get("PackName");
break;
case "localname":
$ret = $this->Get("LocalName");
break;
case "link":
$t = $element->attributes["_template"];
if(strlen($t))
{
$var_list_update["t"] = $t;
}
else
$var_list_update["t"] = $var_list["t"];
$m_var_list_update["lang"] = $this->Get("LanguageId");
$ret = GetIndexURL(2)."?env=".BuildEnv();
unset($var_list_update["t"],$m_var_list_update["lang"]);
break;
case "primary":
$ret = "";
if($this->Get("PrimaryLang")==1)
$ret = "1";
break;
case "icon":
$ret = "";
$icon = $this->Get("IconUrl");
if(strlen($icon)>0)
{
$file = $TemplateRoot."/".$icon;
//echo "File:$file <br>\n";
if(file_exists($file))
$ret = $icon;
}
if(!strlen($ret))
$ret = $element->attributes["_default"];
//echo $ret;
break;
}//switch
}//if
return $ret;
}
function AdminIcon()
{
global $imagesURL;
$file = $imagesURL."/itemicons/icon16_language";
if($this->Get("PrimaryLang")==1)
{
$file .= "_primary.gif";
}
else
{
if($this->Get("Enabled")==0)
{
$file .= "_disabled";
}
$file .= ".gif";
}
return $file;
}
}
class clsLanguageList extends clsItemCollection
{
var $m_Primary;
function clsLanguageList()
{
$this->clsItemCollection();
$this->SourceTable = GetTablePrefix()."Language";
$this->classname = "clsLanguage";
$this->AdminSearchFields = array("PackName","LocalName");
}
function SetPrimary($lang_id)
{
$sql = "UPDATE ".$this->SourceTable." SET PrimaryLang=0 ";
$this->adodbConnection->Execute($sql);
$l = $this->GetItem($lang_id);
$l->Set("PrimaryLang","1");
$l->Update();
$this->m_Primary =$lang_id;
}
function GetPrimary($Field="LanguageId")
{
if(!$this->m_Primary)
{
$sql = "SELECT * FROM ".$this->SourceTable." WHERE PrimaryLang=1";
$rs = $this->adodbConnection->Execute($sql);
if($rs && !$rs->EOF)
{
$l = $rs->fields[$Field];
}
else
$l = 0;
$this->m_Primary=$l;
}
else
$l = $this->m_Primary;
return $l;
}
function LoadAllLanguages()
{
$sql = "SELECT * FROM ".$this->SourceTable;
$this->Query_Item($sql);
}
- function &AddLanguage($PackName,$LocalName,$Enabled,$Primary, $IconUrl="",$Datefmt,$TimeFmt,$Dec,$Thousand)
+ function &AddLanguage($PackName,$LocalName,$Enabled,$Primary, $IconUrl="",$Datefmt,$TimeFmt,$Dec,$Thousand,$Charset)
{
$l = new clsLanguage();
$l->tablename = $this->SourceTable;
$l->Set(array("PackName","LocalName","Enabled","PrimaryLang","IconUrl","DateFormat","TimeFormat",
- "DecimalPoint","ThousandSep"),
- array($PackName,$LocalName,$Enabled,$Primary,$IconUrl,$Datefmt,$TimeFmt,$Dec,$Thousand));
+ "DecimalPoint","ThousandSep",'Charset'),
+ array($PackName,$LocalName,$Enabled,$Primary,$IconUrl,$Datefmt,$TimeFmt,$Dec,$Thousand,$Charset));
$l->Dirty();
$l->Create();
return $l;
}
function EditLanguage($id,$PackName,$LocalName,$Enabled,$Primary, $IconUrl="",$Datefmt,$TimeFmt,$Dec,$Thousand,$Charset)
{
$l = $this->GetItem($id);
$l->Set(array("PackName","LocalName","Enabled","PrimaryLang","IconUrl","DateFormat","TimeFormat",
"DecimalPoint","ThousandSep",'Charset'),
array($PackName,$LocalName,$Enabled,$Primary,$IconUrl,$Datefmt,$TimeFmt,$Dec,$Thousand,$Charset));
$l->Update();
return $l;
}
function DeleteLanguage($id)
{
$l = $this->GetItem($id);
$l->Delete();
}
function CopyFromEditTable()
{
global $objSession;
$GLOBALS['_CopyFromEditTable']=1;
$edit_table = $objSession->GetEditTable($this->SourceTable);
$idlist = array();
$sql = "SELECT * FROM $edit_table";
$this->Clear();
$rs = $this->adodbConnection->Execute($sql);
while($rs && !$rs->EOF)
{
$data = $rs->fields;
$c = $this->AddItemFromArray($data);
$c->Dirty();
if($data["LanguageId"]>0)
{
$c->Update();
}
else
{
$oldid = $c->Get("LanguageId");
$c->UnsetIdField();
$c->Create();
$id = $c->Get("LanguageId");
$phrase_table = $objSession->GetEditTable("Phrase");
$message_table = $objSession->GetEditTable("EmailMessage");
$sql = "UPDATE $phrase_table SET LanguageId=$id WHERE LanguageId=$oldid";
$this->adodbConnection->Execute($sql);
$sql = "UPDATE $message_table SET LanguageId=$id WHERE LanguageId=$oldid";
$this->adodbConnection->Execute($sql);
}
$rs->MoveNext();
}
unset($GLOBALS['_CopyFromEditTable']);
}
function ExportPhrases($file,$LangIds=NULL,$PhraseTypes=null)
{
$output = array();
$this->Clear();
$where_parts = Array();
if( isset($LangIds) ) $where_parts[] = 'LanguageId IN ('.$LangIds.')';
$where = count($where_parts) ? ' WHERE '.implode(' AND ', $where_parts) : '';
$this->Query_Item($sql = 'SELECT * FROM '.$this->SourceTable.$where);
$objXML = new xml_doc();
$RootNode =& $objXML->getTagByID($objXML->createTag("LANGUAGES"));
$ret = 0;
if($this->NumItems()>0)
{
$phrase_where = isset($PhraseTypes) ? ' AND PhraseType IN ('.$PhraseTypes.')' : '';
$event_where = isset($PhraseTypes) ? ' AND Type+1 IN ('.$PhraseTypes.')' : '';
foreach($this->Items as $l)
{
$LangRoot =& $objXML->getTagByID($RootNode->addChild($objXML,"LANGUAGE",array("PackName"=>$l->Get("PackName")),""));
$LangRoot->addChild($objXML,"DATEFORMAT",array(),$l->Get("DateFormat"));
$LangRoot->addChild($objXML,"TIMEFORMAT",array(),$l->Get("TimeFormat"));
$LangRoot->addChild($objXML,"DECIMAL",array(),$l->Get("DecimalPoint"));
$LangRoot->addChild($objXML,"THOUSANDS",array(),$l->Get("ThousandSep"));
$LangRoot->addChild($objXML,"CHARSET",array(),$l->Get("Charset"));
$PhraseRoot =& $objXML->getTagByID($LangRoot->addChild($objXML,"PHRASES"));
$sql = "SELECT * FROM ".GetTablePrefix()."Phrase WHERE LanguageId=".$l->Get("LanguageId").$phrase_where;
$rs=$this->adodbConnection->Execute($sql);
while($rs && ! $rs->EOF)
{
$PhraseRoot->addChild($objXML,"PHRASE",array("Label"=>$rs->fields["Phrase"],"Type"=>$rs->fields["PhraseType"]),base64_encode($rs->fields["Translation"]));
$rs->MoveNext();
}
$EventRoot =& $objXML->getTagByID($LangRoot->addChild($objXML,"EVENTS"));
$ev = GetTablePrefix()."Events";
$em = GetTablePrefix()."EmailMessage";
$sql = "SELECT $em.*,$ev.Event,$ev.Type FROM $em INNER JOIN $ev ON ($em.EventId=$ev.EventId) WHERE LanguageId=".$l->Get("LanguageId").$event_where;
$rs = $this->adodbConnection->Execute($sql);
while($rs && !$rs->EOF)
{
$EventRoot->AddChild($objXML,"EVENT",array("MessageType"=>$rs->fields["MessageType"],"Event"=>$rs->fields["Event"],"Type"=>$rs->fields["Type"]),base64_encode($rs->fields["Template"]));
$rs->MoveNext();
}
}
$objXML->generate();
$objXML->xml = str_replace("&","&amp;",$objXML->xml);
$fp = @fopen($file,"w");
@fputs($fp,$objXML->xml);
@fclose($fp);
}
return file_exists($file);
}
function ReadImportTable($TableName,$SetEnabled=0,$Types="0,1",$OverwitePhrases=FALSE,
$MaxInserts=100,$Offset=0)
{
global $objPhraseList;
if(!is_object($objPhraseList))
$objPhraseList = new clsPhraseList();
$PhraseList = new clsPhraseList();
$TypeArray = explode(",",$Types);
$Inserts = 0;
$sql = "SELECT * FROM $TableName WHERE PhraseType IN ($Types) LIMIT $Offset,$MaxInserts";
//echo $sql;
//$PhraseList->EnablePaging = false;
$PhraseList->Query_Item($sql);
if($PhraseList->NumItems()>0)
{
foreach($PhraseList->Items as $i)
{
$p = $objPhraseList->GetPhrase($i->Get("Phrase"),$i->Get("LanguageId"));
//echo "<pre>"; print_r($p); echo "</pre>";
if(is_object($p))
{
if($OverwitePhrases)
{
//$p->debuglevel=1;
$p->Set("Translation",$i->Get("Translation"));
//echo $i->Get("Translation")."<br>";
$p->Set("PhraseType",$i->Get("PhraseType"));
$p->Dirty();
$p->Update();
}
}
else {
//$i->debuglevel=1;
$i->Create();
}
$Inserts++;
}
}
$Offset = $Offset + $Inserts;
return $Offset;
}
function PurgeEditTable()
{
global $objSession;
$edit_table = $objSession->GetEditTable($this->SourceTable);
$this->adodbConnection->Execute("DROP TABLE IF EXISTS $edit_table");
}
}
class clsLanguageCache
{
var $m_CachedLanguage;
var $FullLoad = FALSE;
var $cache;
var $adodbConnection;
var $TemplateName;
var $TemplateCache;
var $TemplateDate;
var $ThemeId;
function clsLanguageCache($LangId=NULL)
{
global $objConfig;
$this->m_CachedLanguage = $LangId;
$this->adodbConnection =&GetADODBConnection();
$this->Clear();
}
function Clear()
{
unset($this->cache);
$this->cache = array();
$this->TemplateCache = array();
}
function LoadLanguage($LangId,$Type)
{
$this->Clear();
$this->m_CachedLanguage = $LangId;
$this->FullLoad = TRUE;
$sql = "SELECT Phrase,Translation FROM ".GetTablePrefix()."Phrase WHERE LanguageId=$LangId AND PhraseType=$Type";
$rs = $this->adodbConnection->Execute($sql);
while($rs && !$rs->EOF)
{
$this->cache[$rs->fields["Phrase"]] = $rs->fields["Translation"];
if(ADODB_EXTENSION>0)
{
adodb_movenext($rs);
}
else
$rs->MoveNext();
}
return (count($this->cache)>0);
}
function GetPhrase($Phrase,$Lang)
{
$t = "";
$sql = "SELECT PhraseId,Phrase,Translation FROM ".GetTablePrefix()."Phrase WHERE Phrase='$Phrase' AND LanguageId='$Lang'";
$rs = $this->adodbConnection->Execute($sql);
if($rs && !$rs->EOF)
{
$t = $rs->fields["Translation"];
$this->TemplateCache[] = $rs->fields["PhraseId"];
}
return $t;
}
function LoadTemplateCache($t, $timeout, $ThemeId)
{
$this->TemplateName = $t;
$this->TemplateDate = 0;
$this->ThemeId = $ThemeId;
if($timeout > 0)
{
$sql = "SELECT * FROM ".GetTablePrefix()."PhraseCache WHERE Template='$t' AND ThemeId=$ThemeId";
$rs = $this->adodbConnection->Execute($sql);
if($rs && !$rs->EOF)
{
$this->TemplateCache = explode(',', $rs->fields['PhraseList']);
$t_length = strlen($rs->fields['PhraseList']) ? 1 : 0;
$this->TemplateDate = $rs->fields["CacheDate"];
if(date("U") < $this->TemplateDate + $timeout || !$t_length)
{
$this->TemplateCache = Array();
$this->TemplateDate=0;
}
}
else
$this->TemplateDate = -1;
}
else
$this->TemplateDate=-2;
}
function LoadCachedVars($LangId)
{
if(count($this->TemplateCache))
{
$values = implode(",",$this->TemplateCache);
$this->FullLoad = FALSE;
$this->m_CachedLanguage = $LangId;
$sql = "SELECT Phrase,Translation FROM ".GetTablePrefix()."Phrase WHERE LanguageId=$LangId AND PhraseId IN ($values)";
$rs = $this->adodbConnection->Execute($sql);
while($rs && !$rs->EOF)
{
$this->cache[$rs->fields["Phrase"]] = $rs->fields["Translation"];
if( defined('ADODB_EXTENSION') && constant('ADODB_EXTENSION') > 0 )
adodb_movenext($rs);
else
$rs->MoveNext();
}
}
}
function SaveTemplateCache()
{
if($this->TemplateDate==0 || $this->TemplateDate==-1)
{
$value = implode(",",$this->TemplateCache);
if($this->TemplateDate==0)
{
$sql = "UPDATE ".GetTablePrefix()."PhraseCache SET PhraseList='$value',CacheDate=".date("U");
$sql .=" WHERE Template='".$this->TemplateName."' AND ThemeId=".$this->ThemeId;
}
else
{
$sql = "INSERT IGNORE INTO ".GetTablePrefix()."PhraseCache (Template,PhraseList,CacheDate,ThemeId) VALUES ('";
$sql .= $this->TemplateName."','$value',".date("U").",".$this->ThemeId.")";
}
$this->adodbConnection->Execute($sql);
}
}
//This function returns a translation for a particular phrase
//if translation is not found then !phrase! is returned.
function GetTranslation($phrase,$language)
{
global $objSession, $LogPhraseLookups,$LangList, $MissingList;
$missing = FALSE;
if(!$this->FullLoad)
{
$this->RefreshCacheStatus($language);
if(!isset($this->cache[$phrase]))
{
$this->cache[$phrase] = $this->GetPhrase($phrase,$language);
$translation = $this->cache[$phrase];
//$translation = "";
}
else
$translation = $this->cache[$phrase];
}
else
{
$translation = $this->cache[$phrase];
}
if(!strlen($translation))
{
$missing = TRUE;
if($language != 1)
{
$translation=$this->GetTranslation($phrase,1);
}
else
{
$translation = "!".$phrase."!";
}
}
if($LogPhraseLookups==TRUE)
{
//if(!is_array($LangList))
// $LangList = array();
//$LangList[$phrase] = $LangList;
if($missing)
{
if(!is_array($MissingList))
{
$MissingList = array();
}
if(!in_array($phrase,$MissingList))
$MissingList[] = $phrase;
}
}
return $translation;
}
//This function checks if cache is current for current language
//if not clear it out
function RefreshCacheStatus($language)
{
//First remember what language we are caching
// if(!isset($this->m_CachedLanguage))
// $this->m_CachedLanguage = $language;
//If this is the different language, then clear the cache
// if($this->m_CachedLanguage != $language)
// {
// $this->Clear();
// $this->m_CachedLanguage = $language;
// }
}
}
?>
Property changes on: trunk/kernel/include/language.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.14
\ No newline at end of property
+1.15
\ No newline at end of property
Index: trunk/tools/flush_tables.php
===================================================================
--- trunk/tools/flush_tables.php (nonexistent)
+++ trunk/tools/flush_tables.php (revision 912)
@@ -0,0 +1,27 @@
+<?php
+
+ require_once 'tool_lib.php';
+
+ switch ($_REQUEST['action'])
+ {
+ case 'drop':
+ $sql_prefix='DROP TABLE IF EXISTS';
+ break;
+
+ case 'delete':
+ $sql_prefix='DELETE FROM';
+ break;
+
+ default:
+ $sql_prefix='';
+ break;
+ }
+ if(!$sql_prefix) die('Specify valid action');
+
+ $tables=$tool_db->GetCol('SHOW TABLES LIKE \''.TABLE_PREFIX.'%\'');
+ foreach($tables as $table)
+ {
+ $tool_db->Query($sql_prefix.' '.$table);
+ }
+
+?>
\ No newline at end of file
Property changes on: trunk/tools/flush_tables.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.1
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/tools/xml2txt.php
===================================================================
--- trunk/tools/xml2txt.php (nonexistent)
+++ trunk/tools/xml2txt.php (revision 912)
@@ -0,0 +1,70 @@
+<?php
+ define('BASE_PATH', $_SERVER['DOCUMENT_ROOT'].'/in-portal');
+
+ define('DIR_PREFIX',BASE_PATH.'/admin/export');
+ define('SRC_NAME', BASE_PATH.'/admin/export/arabic.lang');
+ define('DST_NAME', BASE_PATH.'/admin/export/arabic.txt');
+
+ require_once BASE_PATH.'/kernel/include/xml.php';
+
+ $xml2txt_map=Array( 'DATEFORMAT'=>'DateFormat','TIMEFORMAT'=>'TimeFormat',
+ 'DECIMAL'=>'Decimal','THOUSANDS'=>'Thousands',
+ 'CHARSET'=>'Charset');
+
+ $fp = fopen(SRC_NAME,'r');
+ $xml = fread($fp,filesize(SRC_NAME));
+ fclose($fp);
+
+ $objInXML = new xml_doc($xml);
+ unset($xml);
+ $objInXML->parse();
+ $objInXML->getTag(0,$name,$attribs,$contents,$tags);
+
+ $fp=fopen(DST_NAME,'w');
+
+ foreach($tags as $t)
+ {
+ $LangRoot =& $objInXML->getTagByID($t);
+ fwrite($fp,'PackName='.$LangRoot->attributes['PACKNAME']."\n");
+
+ foreach($LangRoot->children as $tag)
+ {
+ switch($tag->name)
+ {
+ case 'PHRASES':
+ $tag_index = 0; $tag_count = count($tag->children);
+ while($tag_index < $tag_count)
+ {
+ $inner_tag =& $tag->children[$tag_index];
+ $Phrase = $inner_tag->attributes['LABEL'];
+ $Translation = $inner_tag->contents;
+ $PhraseType = $inner_tag->attributes['TYPE'];
+ fwrite($fp,'P_='.$Phrase.';'.$Translation.';'.$PhraseType."\n");
+ $tag_index++;
+ }
+ break;
+
+ case 'EVENTS':
+ $tag_index = 0; $tag_count = count($tag->children);
+ while($tag_index < $tag_count)
+ {
+ $inner_tag =& $tag->children[$tag_index];
+ $event = $inner_tag->attributes["EVENT"];
+ $MsgType = strtolower($inner_tag->attributes["MESSAGETYPE"]);
+ $template = $inner_tag->contents;
+ $Type = $inner_tag->attributes["TYPE"];
+
+ fwrite($fp,'E_='.$event.';'.$template.';'.$Type.';'.$MsgType."\n");
+ $tag_index++;
+ }
+ break;
+
+ default:
+ fwrite($fp,$xml2txt_map[$tag->name].'='.base64_encode($tag->contents)."\n");
+ break;
+ }
+ }
+ }
+
+ fclose($fp);
+?>
\ No newline at end of file
Property changes on: trunk/tools/xml2txt.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.1
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/tools/tool_lib.php
===================================================================
--- trunk/tools/tool_lib.php (nonexistent)
+++ trunk/tools/tool_lib.php (revision 912)
@@ -0,0 +1,54 @@
+<?php
+
+ /*
+ * $tool_db - connection to in-portal database
+ * TABLE_PREFIX - prefix for each table in that db
+ * BASE_PATH - path to in-portal root directory
+ */
+
+ // all things tool need to survive
+ define('CONFIG_FILE','../config.php');
+
+ require_once '../kernel/include/db.class.php';
+
+ // get db connection information from config
+ $db_info=Array();
+ $file=file(CONFIG_FILE);
+ foreach($file as $line)
+ {
+ if( substr($line,0,2) == 'DB' )
+ {
+ preg_match('/(.*) = "(.*)"/',$line,$rets);
+ $db_info[$rets[1]]=$rets[2];
+ }
+ elseif( substr($line,0,5) == 'Table' )
+ {
+ preg_match('/(.*) = "(.*)"/',$line,$rets);
+ define('TABLE_PREFIX',$rets[2]);
+ }
+ }
+
+ // connect to in-portal database
+ $tool_db=new DBConnection($db_info['DBType']);
+ $tool_db->Connect($db_info['DBHost'],$db_info['DBUser'],$db_info['DBUserPassword'],$db_info['DBName']);
+
+ $sub_folder=$tool_db->GetOne('SELECT VariableValue FROM '.TABLE_PREFIX.'ConfigurationValues WHERE VariableName=\'Site_Path\'');
+ define('BASE_PATH', $_SERVER['DOCUMENT_ROOT'].rtrim($sub_folder,'/'));
+ unset($sub_folder);
+
+ /**
+ * Same as print_r, but for html pages
+ *
+ * @param string $s
+ * @param bool $returnResult
+ * @return string
+ * @access public
+ */
+ function tool_printPre($s,$returnResult=false)
+ {
+ $ret='<pre>'.print_r($s,true).'</pre>';
+ if($returnResult) return $ret;
+ echo $ret;
+ }
+
+?>
\ No newline at end of file
Property changes on: trunk/tools/tool_lib.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.1
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/tools/phrase_locator.php
===================================================================
--- trunk/tools/phrase_locator.php (revision 911)
+++ trunk/tools/phrase_locator.php (revision 912)
@@ -1,88 +1,71 @@
<?php
- // change next 2 lines only
- define('HOST_PREFIX','alex');
- define('DB_PREFIX', 'UpG_');
-
- // don't change anything here
- define('DB_USER','dev');
- define('DB_PASS','dev-25-sql');
- define('DB_HOST','localhost');
- define('DB_BASE',HOST_PREFIX.'_in_portal');
- $dir = '/www/'.HOST_PREFIX.'/in-portal/';
+ require_once 'tool_lib.php';
$phrases = Array();
- scanDir($dir);
+ scanDir(BASE_PATH.'/');
function scanDir($FolderPath)
{
global $phrases;
+ $scan_types=Array('php','js','tpl');
$FolderHandle = opendir($FolderPath);
if($FolderHandle)
{
while( false !== ($file = readdir($FolderHandle)) )
{
- if( $file == '.' || $file == '..' ) continue;
+ if($file == '.' || $file == '..') continue;
$file = $FolderPath.$file;
if( is_dir($file) )
{
scanDir($file.'/');
}
- elseif( is_file($file) && in_array(substr($file,strrpos($file, '.') + 1), Array('php','js','tpl')) )
+ elseif( is_file($file) && in_array(substr($file,-3),$scan_types) )
{
$filedata = file_get_contents($file);
preg_match_all('/\'(lu_.*|la_.*)\'/U',$filedata,$rets);
foreach ($rets[1] as $phrase_name) {
$phrases[strtolower($phrase_name)] = 1;
}
preg_match_all('/"(lu_.*|la_.*)"/U',$filedata,$rets);
foreach ($rets[1] as $phrase_name) {
$phrases[strtolower($phrase_name)] = 1;
}
}
}
closedir($FolderHandle);
}
}
- //print_r($phrases);
+ //tool_printPre($phrases);
- $mysql_link = mysql_connect(DB_HOST,DB_USER,DB_PASS);
- mysql_select_db(DB_BASE,$mysql_link);
-
- $sql = 'SELECT LOWER(Phrase) AS Phrase FROM '.DB_PREFIX.'Phrase WHERE LanguageId = 1';
- $rs = mysql_query($sql,$mysql_link);
- while( ($row = mysql_fetch_array($rs)) )
+ $sql = 'SELECT LOWER(Phrase) FROM '.TABLE_PREFIX.'Phrase WHERE LanguageId = 1';
+ $db_phrases=$tool_db->GetCol($sql);
+ foreach ($db_phrases as $phrase)
{
- unset($phrases[ $row['Phrase'] ]); // phrase is translated
+ unset($phrases[$phrase]); // phrase is translated
}
- mysql_free_result($rs);
$ret = Array();
foreach($phrases as $phrase => $dummy_value)
{
$ret[] = $phrase;
}
- print_pre($ret);
+ tool_printPre($ret);
- if( unlink($dir.'new_phrases.txt') )
+ if( unlink(BASE_PATH.'/new_phrases.txt') )
{
- $fp = fopen($dir.'new_phrases.txt','w');
+ $fp = fopen(BASE_PATH.'/new_phrases.txt','w');
foreach ($ret as $phrase)
{
fwrite($fp,$phrase."\n");
}
fclose($fp);
}
else
{
die('Can\'t create file <b>new_phrases.txt</b>');
}
-
- function print_pre($s)
- {
- echo '<pre>',print_r($s,true),'</pre>';
- }
?>
\ No newline at end of file
Property changes on: trunk/tools/phrase_locator.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.4
\ No newline at end of property
+1.5
\ No newline at end of property

Event Timeline