Index: trunk/kernel/action.php
===================================================================
diff -u -r842 -r850
--- trunk/kernel/action.php (.../action.php) (revision 842)
+++ trunk/kernel/action.php (.../action.php) (revision 850)
@@ -1156,25 +1156,26 @@
}
break;
case "m_theme_add":
- $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"],
- (int)$_POST["CacheTimeout"],$Primary);
-
$ado = &GetADODBConnection();
- $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."
\n";
- if ($Primary==1)
+ $rs = $ado->Execute("SELECT COUNT(*) as c FROM ".GetTablePrefix().'Theme WHERE Name="'.$_POST["name"].'"');
+ if(!$rs->fields["c"])
{
- $objEditItems->SetPrimaryTheme($_POST["ThemeId"]);
- }
- $ado->Execute($sql);
+ $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."
\n";
+ $ado->Execute($sql);
+ }
break;
case "m_theme_edit":
$objEditItems = new clsThemeList();
@@ -1185,10 +1186,10 @@
$objEditItems->EditTheme($_POST["ThemeId"],$_POST["name"],$_POST["description"],
(int)$_POST["enabled"],$Primary,(int)$_POST["CacheTimeout"]);
- if ($Primary==1)
- {
- $objEditItems->SetPrimaryTheme($_POST["ThemeId"]);
- }
+// if ($Primary==1)
+// {
+// $objEditItems->SetPrimaryTheme($_POST["ThemeId"]);
+// }
break;
case "m_theme_delete":
Index: trunk/kernel/include/theme.php
===================================================================
diff -u -r766 -r850
--- trunk/kernel/include/theme.php (.../theme.php) (revision 766)
+++ trunk/kernel/include/theme.php (.../theme.php) (revision 850)
@@ -152,10 +152,11 @@
function IsWriteablePath($new_file = false)
{
+
$path = $this->FullPath();
$path = str_replace('//','/',$path);
$ret = $new_file ? is_writable(dirname($path)): is_writable($path);
-
+
if(!$ret)
{
$this->SetError(THEME_ERROR_1, 1);
@@ -245,8 +246,10 @@
$f->Set(array("FilePath","FileName","ThemeId","FileType","Description"),
array($Path,$Name,$ThemeId,$Type,$Description));
$f->Create();
- if($contents!=NULL)
- $f->SaveFileContents($contents);
+ if($contents!==NULL)
+ {
+ $f->SaveFileContents($contents,$Name);
+ }
//echo $f->Get("FilePath")."/".$f->Get("FileName")."
\n";
return $f;
}
@@ -473,6 +476,16 @@
$dir = $this->ThemeDirectory();
if(!is_dir($dir))
mkdir($dir);
+ if(is_dir($dir))
+ {
+ $fp = fopen($dir.'/index.tpl',"w");
+ if($fp)
+ {
+ fwrite($fp,'');
+ fclose($fp);
+ }
+
+ }
}
function Delete()
@@ -584,6 +597,7 @@
$t->Set(array("Name","Description","Enabled","PrimaryTheme","CacheTimeout"),
array($Name,$Description,$Enabled,$Primary,$CacheTimeout));
$t->Create();
+ $t->Files->ThemeId=$t->Get("ThemeId");
if($Primary==1)
{
$sql = "UPDATE ".$this->SourceTable." SET PrimaryTheme=0 WHERE ThemeId != ".$t->Get("ThemeId");
@@ -595,6 +609,13 @@
function EditTheme($ThemeId,$Name,$Description,$Enabled,$Primary, $CacheTimeout)
{
$t = $this->GetItem($ThemeId);
+ $oldName = $t->Get("Name");
+ if($oldName!=$Name)
+ {
+ $dir=dirname($t->ThemeDirectory());
+ if(!rename($dir.'/'.$oldName,$dir.'/'.$Name))
+ $Name=$oldName;
+ }
$t->Set(array("Name","Description","Enabled","PrimaryTheme","CacheTimeout"),
array($Name, $Description, $Enabled, $Primary, $CacheTimeout));
$t->Dirty();
@@ -646,41 +667,52 @@
$path = $pathtoroot."themes";
$themes = array();
+ $HDDThemes=Array();
if ($dir = @opendir($path))
{
while (($file = readdir($dir)) !== false)
{
if($file !="." && $file !=".." && substr($file,0,1)!="_")
{
- if(is_dir($path."/".$file))
+ if(is_dir($path."/".$file)&&file_exists($path."/".$file.'/index.tpl'))
{
$file = strtolower($file);
$themes[$file]=0;
+ $HDDThemes[]=$file;
}
}
}
}
closedir($dir);
+
+ $sql = 'SELECT ThemeId AS i,Name AS n FROM '.$this->SourceTable;
+ $DBThemes=Array();
+ if($rs = $this->adodbConnection->Execute($sql))
+ {
+ while(!$rs->EOF)
+ {
+ $DBThemes[$rs->fields['i']] = $fullpath.$rs->fields['n'];
+ $rs->MoveNext();
+ }
+ $rs->Free();
+ }
+
+ $missingThemes=array_diff($HDDThemes,$DBThemes);
+ $orphanThemes=array_diff($DBThemes,$HDDThemes);
+
+ if($orphanThemes)
+ {
+ $sql = 'DELETE FROM '.$this->SourceTable.' WHERE ThemeId IN('.join(',',array_keys($orphanThemes)).')';
+ $this->adodbConnection->Execute($sql);
+ $sql = 'DELETE FROM '.GetTablePrefix().'ThemeFiles WHERE ThemeId IN('.join(',',array_keys($orphanThemes)).')';
+ $this->adodbConnection->Execute($sql);
+ }
$this->Clear();
- $this->Query_Item("SELECT * FROM ".$this->SourceTable);
- foreach($this->Items as $i)
- {
- $n = strtolower($i->Get("Name"));
- $themes[$n] = $i->Get("ThemeId");
- }
- $names = array_keys($themes);
- for($i=0;$iAddTheme($name,"New Theme",0,0);
- $themes[$name] = $t->Get("ThemeId");
- }
- }
- $where = implode(",",array_values($themes));
- $sql = "DELETE FROM ".$this->SourceTable." WHERE ThemeId NOT IN ($where)";
+ foreach($missingThemes as $theme)
+ {
+ $t=$this->AddTheme($theme,"New Theme",0,0);
+ $t->Files->FindMissingFiles($t->Get('Name'));
+ }
}
function CopyFromEditTable()