299 lines
9.2 KiB
PHP
299 lines
9.2 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
$EditStoresEditId=0;
|
||
|
|
|
||
|
|
function WriteStoreList($ParentId, $ParentIsLocked)
|
||
|
|
{
|
||
|
|
global $GlobalMysqlHandler;
|
||
|
|
global $GlobalContent;
|
||
|
|
global $GlobalTemplate;
|
||
|
|
global $EditStoresEditId;
|
||
|
|
|
||
|
|
$ListQuery="SELECT `Id` , `Name` FROM `Storages` WHERE `ParentId` =$ParentId";
|
||
|
|
$ListQuery=mysqli_query($GlobalMysqlHandler, $ListQuery);
|
||
|
|
|
||
|
|
if (!$ParentId || NestedListVisibilityIsSet($ParentId, 'EditStorage'))
|
||
|
|
$GlobalContent .= "<ul style=\"display:block;\">\n";
|
||
|
|
else
|
||
|
|
$GlobalContent .= "<ul style=\"display:none;\">\n";
|
||
|
|
|
||
|
|
if (mysqli_num_rows($ListQuery))
|
||
|
|
{
|
||
|
|
while ($ListData=mysqli_fetch_array($ListQuery))
|
||
|
|
{
|
||
|
|
if ($EditStoresEditId
|
||
|
|
&& ($EditStoresEditId==$ListData['Id'])
|
||
|
|
&& !( LockIsActive('Storages',$ListData['Id']) || $ParentIsLocked)
|
||
|
|
)
|
||
|
|
{ //edit entry
|
||
|
|
$GlobalContent .= " <li>\n";
|
||
|
|
$GlobalContent .= ' <a href="index.php?Page=EditStores&ToDo=DeleteStore&Id='.$ListData['Id'].'" title="'.LangSpellHtml('TagTitleDelete').'">'.OtherGetIcon('Delete',"Button").'</a>';
|
||
|
|
$GlobalContent .= ' <form action="index.php?Page=EditStores&ToDo=EditStoreSave" method="post">';
|
||
|
|
$GlobalContent .= ' <input type="hidden" name="Id" value="'.$ListData['Id'].'">';
|
||
|
|
$GlobalContent .= '<input type="text" name="Name" value="'.$ListData['Name'].'">';
|
||
|
|
$GlobalContent .= '<select name="MoveToId" title="'.LangSpellHtml('TagTitleMove').'">';
|
||
|
|
if ($ParentId)
|
||
|
|
$GlobalContent .= '<option value="#MOVE#ITEM#UP#">'.LangSpellHtml('TagTitleMoveUp').'</option>';
|
||
|
|
$GlobalContent .= '<option value="" selected>--- '.LangSpellHtml('TagTitleMove').' ---</option>';
|
||
|
|
$MoveItems = NestedLisGetSubelements($ParentId,"Storages");
|
||
|
|
foreach ($MoveItems as $MvItm)
|
||
|
|
{
|
||
|
|
if ($MvItm[0]==$ListData['Id']) continue;
|
||
|
|
$GlobalContent .= '<option value="'.$MvItm[0].'">'.$MvItm[1].'</option>';
|
||
|
|
}
|
||
|
|
$GlobalContent .= "</select>";
|
||
|
|
$GlobalContent .= '<input type="submit" value="'.LangSpellHtml('ButtonSave').'" class="Button">';
|
||
|
|
$GlobalContent .= ' </form>';
|
||
|
|
$GlobalContent .= ' <a href="index.php?Page=EditStores&ToDo=CancelEditStore&Id='.$ListData['Id'].'" title="'.LangSpellHtml('TagTitleCancel').'">'.OtherGetIcon('Cancel',"Button").'</a>' ."\n";
|
||
|
|
$GlobalContent .= " </li>\n";
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{ //just show entry
|
||
|
|
$GlobalContent .= " <li>\n";
|
||
|
|
if (LockIsActive('Storages',$ListData['Id']) || $ParentIsLocked)
|
||
|
|
{
|
||
|
|
$GlobalContent .= ' '.OtherGetIcon('LockActive');
|
||
|
|
$ParentIsLocked = 1;
|
||
|
|
}
|
||
|
|
elseif (UserHasRight('EditStores'))
|
||
|
|
{
|
||
|
|
$GlobalContent .= ' <a href="index.php?Page=EditStores&ToDo=EditStore&Id='.$ListData['Id'].'" target="_top" title="'.LangSpellHtml('TagTitleEdit').'">';
|
||
|
|
$GlobalContent .= OtherGetIcon('Edit',"Button");
|
||
|
|
}
|
||
|
|
$GlobalContent .= " <a href=\"index.php?Page=EditStores&ToDo=OpenSublist&SublistId=".$ListData['Id']."\">".LangStr2Html($ListData['Name'])."</a>";
|
||
|
|
$GlobalContent .= " (".NestedListCountSubElements($ListData['Id'],'Storages').")";
|
||
|
|
$GlobalContent .= " \n</li>\n";
|
||
|
|
}
|
||
|
|
|
||
|
|
WriteStoreList($ListData['Id'],$ParentIsLocked);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (!$EditStoresEditId && UserHasRight('EditStores'))
|
||
|
|
{
|
||
|
|
$GlobalContent .= " <li>\n";
|
||
|
|
$GlobalContent .= ' <form action="index.php?Page=EditStores&ToDo=NewStore&ParentId='.$ParentId.'" method="post">'."\n";
|
||
|
|
$GlobalContent .= ' <input type="text" name="NewStoreName" value="">'."\n";
|
||
|
|
$GlobalContent .= ' <input type="submit" value="'.LangSpellHtml('ButtonNew').'" class="Button">'."\n";
|
||
|
|
$GlobalContent .= ' </form>'."\n";
|
||
|
|
$GlobalContent .= " </li>\n";
|
||
|
|
}
|
||
|
|
$GlobalContent .= "</ul>\n";
|
||
|
|
}
|
||
|
|
|
||
|
|
if (UserHasRight('EditStores'))
|
||
|
|
{
|
||
|
|
/////////////////
|
||
|
|
//edit store save
|
||
|
|
if ($ToDo=="EditStoreSave")
|
||
|
|
{
|
||
|
|
if (isset($_POST['Id']) && $_POST['Id'] && isset($_POST['Name']) && $_POST['Name'])
|
||
|
|
{
|
||
|
|
global $GlobalMysqlHandler;
|
||
|
|
$Id = $_POST['Id'];
|
||
|
|
$Name = $_POST['Name'];
|
||
|
|
$MoveId = (isset($_POST['MoveToId']))? $_POST['MoveToId']:0;
|
||
|
|
|
||
|
|
if ($MoveId)
|
||
|
|
{
|
||
|
|
$MoveQuery = "";
|
||
|
|
if ($MoveId=="#MOVE#ITEM#UP#")
|
||
|
|
{
|
||
|
|
$FirstParentId = NestedListGetParentId($Id,'Storages');
|
||
|
|
$MoveId = NestedListGetParentId($FirstParentId,'Storages');
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
$FirstParentId = NestedListGetParentId($Id,'Storages');
|
||
|
|
}
|
||
|
|
|
||
|
|
$MoveQuery="UPDATE `Storages` SET `ParentId` = '$MoveId' WHERE `Id` =$Id LIMIT 1 ;";
|
||
|
|
|
||
|
|
if (mysqli_query($GlobalMysqlHandler, $MoveQuery))
|
||
|
|
{
|
||
|
|
MessageSuccess(LangSpell('SentenceNestedListMoved'));
|
||
|
|
NestedListVisibilityUnset($FirstParentId,'EditStorage');
|
||
|
|
NestedListVisibilitySet($MoveId,'EditStorage');
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
MessageError(LangSpell('SentenceDatabaseError'));
|
||
|
|
ErrorLog("[edit_stored.php] Db error on moving element with id $Id to parent id $MoveId");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
$ChangeNameQuery="UPDATE `Storages` SET `Name` = '$Name' WHERE `Id` =$Id LIMIT 1 ;";
|
||
|
|
if (!mysqli_query($GlobalMysqlHandler, $ChangeNameQuery))
|
||
|
|
{
|
||
|
|
MessageError(LangSpell('SentenceDatabaseError'));
|
||
|
|
ErrorLog("[edit_stored.php] Db error on naming element with id $Id");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
if (isset($_POST['Name']) && !trim($_POST['Name']))
|
||
|
|
MessageError(LangSpell('EditStoresNoStoreNameGiven'));
|
||
|
|
else
|
||
|
|
{
|
||
|
|
ErrorLog("[edit_stores.php] No Id to move!");
|
||
|
|
MessageError(LangSpell('SentenceUnknownError'));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
$ToDo="";
|
||
|
|
}
|
||
|
|
|
||
|
|
///////////////
|
||
|
|
// delete store
|
||
|
|
if ($ToDo=="DeleteStore")
|
||
|
|
{
|
||
|
|
if (isset($_GET['Id']) && $_GET['Id'])
|
||
|
|
{
|
||
|
|
$Id = $_GET['Id'];
|
||
|
|
if (!LockIsActive('Storages',$Id))
|
||
|
|
{
|
||
|
|
global $GlobalMysqlHandler;
|
||
|
|
$DeleteQuery="DELETE FROM `Storages` WHERE `Id` = $Id LIMIT 1";
|
||
|
|
if (mysqli_query($GlobalMysqlHandler, $DeleteQuery))
|
||
|
|
{
|
||
|
|
MessageSuccess(LangSpell('EditStoresStoreDeleted'));
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
MessageError(LangSpell('SentenceDatabaseError'));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
MessageError(LangSpell('SentenceLockIsActive'));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
ErrorLog("[edit_stores.php] No Id to delete store!");
|
||
|
|
MessageError(LangSpell('SentenceUnknownError'));
|
||
|
|
}
|
||
|
|
$ToDo="";
|
||
|
|
}
|
||
|
|
|
||
|
|
////////////////
|
||
|
|
// add new store
|
||
|
|
if ($ToDo=="NewStore")
|
||
|
|
{
|
||
|
|
if (isset($_GET['ParentId']) && isset($_POST['NewStoreName']))
|
||
|
|
{
|
||
|
|
$ParentId = $_GET['ParentId'];
|
||
|
|
$NewStoreName = $_POST['NewStoreName'];
|
||
|
|
if (LockActivate('Storages',$ParentId))
|
||
|
|
{
|
||
|
|
if (trim($NewStoreName)!="")
|
||
|
|
{
|
||
|
|
global $GlobalMysqlHandler;
|
||
|
|
$InsertQuery="INSERT INTO `Storages` ( `Name` , `ParentId` ) VALUES ( '$NewStoreName', '$ParentId' );";
|
||
|
|
if (mysqli_query($GlobalMysqlHandler, $InsertQuery))
|
||
|
|
{
|
||
|
|
MessageSuccess(LangSpell('EditStoresNewStoreAdded'));
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
MessageError(LangSpell('SentenceDatabaseError'));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
MessageError(LangSpell('EditStoresNoStoreNameGiven'));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
MessageError(LangSpell('SentenceLockIsActive'));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
if (!isset($_GET['ParentId']))
|
||
|
|
ErrorLog("[edit_stores.php] No ParentId to add new store!");
|
||
|
|
if (!isset($_POST['NewStoreName']))
|
||
|
|
ErrorLog("[edit_stores.php] No NewStoreName to add new store!");
|
||
|
|
MessageError(LangSpell('SentenceUnknownError'));
|
||
|
|
}
|
||
|
|
$ToDo="";
|
||
|
|
}
|
||
|
|
|
||
|
|
/////////////
|
||
|
|
// edit store
|
||
|
|
if ($ToDo=="EditStore")
|
||
|
|
{
|
||
|
|
if (isset($_GET['Id']) && $_GET['Id'])
|
||
|
|
{
|
||
|
|
$EditId = $_GET['Id'];
|
||
|
|
if (LockActivate('Storages',$EditId))
|
||
|
|
{
|
||
|
|
$EditStoresEditId=$EditId;
|
||
|
|
//NestedListVisibilityUnset($EditId, 'EditStorage');
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
MessageError(LangSpell('SentenceLockIsActive'));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
ErrorLog("[edit_stores.php] No Id to edit store");
|
||
|
|
MessageError(LangSpell('SentenceUnknownError'));
|
||
|
|
}
|
||
|
|
$ToDo = "";
|
||
|
|
}
|
||
|
|
|
||
|
|
////////////////////
|
||
|
|
// cancel edit store
|
||
|
|
if ($ToDo=="CancelEditStore")
|
||
|
|
{
|
||
|
|
if (isset($_GET['Id']) && $_GET['Id'])
|
||
|
|
{
|
||
|
|
$EditId = $_GET['Id'];
|
||
|
|
if (LockRelease('Storages',$EditId))
|
||
|
|
{
|
||
|
|
$EditStoresEditId=0;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
MessageError(LangSpell('SentenceLockIsActive'));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
ErrorLog("[edit_stores.php] No Id to release loack on storage");
|
||
|
|
MessageError(LangSpell('SentenceUnknownError'));
|
||
|
|
}
|
||
|
|
$ToDo = "";
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if (UserHasRight('EditStores') || UserHasRight('ViewSTPV'))
|
||
|
|
{
|
||
|
|
///////////////
|
||
|
|
// open sublist
|
||
|
|
if ($ToDo=="OpenSublist")
|
||
|
|
{
|
||
|
|
if (isset($_GET['SublistId']) && $_GET['SublistId'])
|
||
|
|
{
|
||
|
|
NestedListVisibilityToggle($_GET['SublistId'], 'EditStorage');
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
ErrorLog("[edit_stores.php] No SublistId to open store!");
|
||
|
|
MessageError(LangSpell('SentenceUnknownError'));
|
||
|
|
}
|
||
|
|
$ToDo="";
|
||
|
|
}
|
||
|
|
|
||
|
|
///////////////
|
||
|
|
// sow stores
|
||
|
|
if ($ToDo=="")
|
||
|
|
WriteStoreList(0,0);
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
MessageError(LangSpell("ScentenceNoUserRights"));
|
||
|
|
}
|
||
|
|
?>
|