<?php
require_once('../php/fredlSession.php');
/****************************************************************
* FREMO Asset Management
* Module: editmodule.php
* Description: Add/edit module information
*
* Created: 10/2004, Dirk Jahnke
* mode=new|insert|edit|update
*
*
* Caller uses only edit, copy or new mode, other modes are used
* by this script. The mode describes the state of this dialogue,
* it follows this life cycle:
* edit --> update (--> update)
* new --> insert --> update (--> update)
* copy --> insert --> update (--> update)
*
*
* $Log: editmodule.php,v $
* Revision 1.12 2005/08/27 20:06:40 dirkj
* Added profile attributes.
*
* Revision 1.11 2005/06/07 21:53:30 dirkj
* Added logDebug calls.
*
* Revision 1.10 2005/05/30 12:29:22 dirkj
* Made multilingual.
*
* Revision 1.9 2005/04/17 17:21:23 dirkj
* Lola Work in progress: step 4
*
* Revision 1.8.2.1 2005/03/30 21:32:49 dirkj
* Work in progress: step 2
*
* Revision 1.8 2005/03/12 18:51:15 dirkj
* Fixed a bug when new objects are saved and edited directly afterwards using the same dialogue.
*
* Revision 1.7 2005/02/06 19:22:27 dirkj
* Read topleveldir from config file.
* Added hint that URLs need to contain the protocol info too.
*
* Revision 1.6 2005/01/24 22:21:14 dirkj
* When copying a module the nreid and fremonid fields are set to null now. Previously
* they contained the id of the source module, which caused a database error as these
* ids have been defined as unique keys (this ist fixed also).
*
* Revision 1.5 2005/01/23 15:16:23 dirkj
* Made favorite file selection functioning.
*
* Revision 1.4 2005/01/20 21:53:19 dirkj
* Changed attribute label "Länge" to "Strecke".
*
* Revision 1.3 2004/11/01 12:35:47 dirkj
* Modified session handling.
*
* Revision 1.2 2004/10/20 18:44:42 dirkj
* Added visibility column to objects and handling of that to control
* security aspects.
*
* Revision 1.1 2004/10/05 06:54:10 dirkj
* Initial Revision.
*
****************************************************************/
require_once '../php/sessionhelpers.inc.php';
require_once '../php/uihelpers.inc.php';
require_once '../php/apphelpers.inc.php';
require_once '../lib/module.php';
require_once '../lib/lang.php';
$usrObj=getUserObject();
$l = new Lang($usrObj->langid, 'editmodule', 'module,general');
print "<html>";
print "<head>";
print '<link rel="stylesheet" type="text/css" href="../'.$myStyleSheet.'">';
print '<script language="JavaScript" src="../lib/favorit.js"></script>';
print "</head>";
print '<body class=right>';
$topdir=$fredlConfig->get('app','rooturl');
$mode=GET2Var('mode');
$module = new Module();
switch ($mode)
{
case 'edit':
$moduleid=GET2Var('moduleid');
$module->dbRead($moduleid);
print '<h1>'.$l->get('editmodule-title','Modul ändern').'</h1>';
$newMode="update";
break;
case 'copy':
$moduleid=GET2Var('moduleid');
$module->dbRead($moduleid);
print '<h1>'.$l->get('copymodule-title','Modul kopieren').'</h1>';
$newMode="insert";
$module->set('moduleid',0);
$module->set('ownerid',$usrObj->id);
$module->set('nreid',null);
$module->set('fremonid',null);
break;
case 'new':
$module->set('ownerid',$usrObj->id);
$moduleid=0;
$module->set('moduleid',$moduleid);
$newMode="insert";
print '<h1>'.$l->get('newmodule','Modul neu anlegen').'</h1>';
break;
case 'insert':
$module->getFromPOST('new');
$module->dbWrite();
$moduleid=$module->get('moduleid');
print '<p>';
$msg=sprintf($l->get('module-added-msg', 'Modul %s angelegt.'),$module->get('name') . " (id=$moduleid) ");
print $msg;
logAudit("editmodule.php: $msg");
addWnfm($usrObj->id, "new module", $msg);
$newMode="update";
// specify title:
print '<h1>'.$l->get('editmodule-title','Modul ändern').'</h1>';
break;
case 'update':
$module->getFromPOST('new');
$module->dbWrite();
$moduleid=$module->get('moduleid');
$msg = sprintf($l->get('module-changed-msg', 'Modul %s geändert.'), $module->get('name') . " (id=$moduleid) ");
print "<p>$msg</p>";
logAudit("editmodule.php: $msg");
$newMode="update";
// specify title:
print '<h1>'.$l->get('editmodule-title','Modul ändern').'</h1>';
break;
default:
echo "<p>ERROR: Unknown mode -$mode-</p>";
break;
}
logDebug("module-edit mode=$mode | moduleid=$moduleid ");
echo "<form action='editmodule.php?mode=$newMode' method='post'>";
// ===== General Section =====
echo '<fieldset><legend><b>'.$l->get('general-module','Modul').'</b></legend>';
echo "<table>";
// prepare to display data:
echo '<tr><td></td>
<td><input type="hidden"
name="newmoduleid"
size="5"
maxlength="5"
value="'.$module->get('moduleid').'"
readonly></td>';
echo '<input type="hidden" name="newownerid" value="'.$module->get('ownerid').'">';
echo '</tr>';
// N-RE ID field
echo ' <tr><td>'.$l->get('module-nreid','N-RE ID:').'</td>
<td><input type="Text"
name="newnreid"
size="4"
maxlength="5"
value="'.$module->get('nreid').'">
</td></tr>';
// Fremo-N ID field
echo ' <tr><td>'.$l->get('module-fremonid', 'Fremo-N ID:').' </td>
<td>N-<input type="Text"
name="newfremonid"
size="4"
maxlength="5"
value="'.$module->get('fremonid').'">
</td></tr>';
// Module Type field
echo '<tr><td>'.$l->get('module-type','Typ:').' </label></td>
<td>';
displayLookupSelection("moduletype", $module->get('moduletypeid'), "newmoduletypeid", $usrObj->langid);
echo '</td></tr>';
// Module Topic field
echo ' <tr><td>'.$l->get('module-topic','Name/Thema:').' </td>
<td><input type="Text"
name="newname"
size="40"
maxlength="100"
value="'.$module->get('name').'">
</td></tr>';
// Description field
echo '<tr><td>'.$l->get('general-description-colon','Beschreibung:').' </td>
<td><input type="Text" name="newdescription" size="60" maxlength="250" value="'.$module->get('description').'"></td></tr>';
echo '</table></fieldset>';
// ===== Geometry Section =====
// +----------------+----------------------+
// | Track length | Profile 1 <IMAGE> |
// | Angle | |
// | Radius | Profile 2 <IMAGE> |
// | Tracks | |
// +---------------------------------------+
//
echo ' <fieldset><legend><b>'.$l->get('module-geomentry','Geometrie').'</b></legend><table>';
echo '<tr><td><table>';
// Track length field
echo ' <tr><td>'.$l->get('module-tracklength','Strecke [mm]:').' </td>
<td><input type="Text"
name="newlength"
size="5"
maxlength="5"
value="'.$module->get('length').'">
</td></tr>';
// Module angle field
echo ' <tr><td>'.$l->get('module-angle', 'Winkel [Grad]:').' </td>
<td><input type="Text"
name="newangle"
size="5"
maxlength="5"
value="'.$module->get('angle').'">
</td></tr>';
echo ' <tr><td>'.$l->get('module-radius', 'Radius [mm]:').' </td>
<td><input type="Text"
name="newradius"
size="5"
maxlength="5"
value="'.$module->get('radius').'">
</td></tr>';
echo ' <tr><td>'.$l->get('module-tracks','Gleise:').' </td>
<td><input type="Text"
name="newtracks"
size="5"
maxlength="5"
value="'.$module->get('tracks').'">
</td></tr>';
echo '</table></td>
<td width=80> </td>
<td valign="top"><table>';
echo '<tr><td>'.$l->get('module-profile1','Profil 1').'</td><td>';
displayLookupSelection("moduleprofile", $module->get('profile1'), "newprofile1", $usrObj->langid);
echo '</td><td></td></tr>';
echo '<tr><td>'.$l->get('module-profile2','Profil 2').'</td><td>';
displayLookupSelection("moduleprofile", $module->get('profile2'), "newprofile2", $usrObj->langid);
echo '</td><td></td></tr>';
echo '</table></td></tr>';
echo '</table></fieldset>';
// ===== Technique Section =====
echo ' <fieldset><legend><b>'.$l->get('module-technique','Technik').'</b></legend><table>';
echo '<tr><td><label>'.$l->get('module-tracktype','Gleismaterial:').' </label></td><td>';
displayLookupSelection("tracktype", $module->get('tracktype'), "newtracktype", $usrObj->langid);
echo '</td></tr>';
echo '</table><table>';
echo ' <tr><td>'.$l->get('module-can-be-used-by-wheeltype','Befahrbar mit').'</td>';
echo ' <td align=right><label>'.$l->get('module-wheel-nem','NEM:').' </label></td><td><input type="Checkbox" name="newradnem" ';
if ($module->get('radnem')) echo 'checked';
echo '></td></tr>';
echo ' <tr><td></td><td align=right><label>'.$l->get('module-wheel-05','0,5:').' </label></td><td><input type="Checkbox" name="newradc40" ';
if ($module->get('radc40')) echo 'checked';
echo '></td></tr>';
echo ' <tr><td></td><td align=right><label>'.$l->get('module-wheel-fiNe', 'fiNe:').' </label></td><td><input type="Checkbox" name="newradfine" ';
if ($module->get('radfine')) echo 'checked';
echo '></td></tr>';
echo '<tr><td> </td></tr>';
echo '<tr><td><label>'.$l->get('module-electrics','Elektrik:').' </label></td>';
echo ' <td align=right><label>'.$l->get('module-electrics-dcc','DCC-Digital:').' </label></td><td><input type="Checkbox" name="newdcccompatible" ';
if ($module->get('dcccompatible')) echo 'checked';
echo '></td></tr>';
echo ' <tr><td></td><td align=right><label>'.$l->get('module-electrics-2ndanalogue','Blindleitung:').' </label></td><td><input type="Checkbox" name="newanaloge2pairs" ';
if ($module->get('analoge2pairs')) echo 'checked';
echo '></td></tr>';
echo '</table></fieldset>';
// ===== More Info Section =====
echo ' <fieldset><legend><b>'.$l->get('module-more-info','Weitere Informationen').'</b></legend><table>';
echo '<tr><td> </td><td align=right>'.$l->get('module-url-hint','URLs inklusive Protokollangabe, also http://, ftp:// usw.').'</td></tr>';
echo ' <tr><td><label>'.$l->get('module-infolink-1','Info-Link 1:').' </label></td><td><input type="Text" name="newinfotxt1" size="50" maxlength="250" value="'.$module->get('infotxt1').'">
<label>URL:</label> <input type="Text" name="newinfolink1" size="50" maxlength="100" value="'.$module->get('infolink1').'">';
if (userHasAccess($usrObj->id, 'filefavorites'))
{
echo '<button type=button onClick="javascript:moveFav2Field(\''.$topdir.'\',\'newinfolink1\',\'newinfotxt1\');" >';
echo '<img src="../img/favorit.gif" alt="Favorit übernehmen" ></button>';
}
echo ' </td></tr>';
echo ' <tr><td><label>'.$l->get('module-infolink-2','Info-Link 2:').' </label></td><td><input type="Text" name="newinfotxt2" size="50" maxlength="250" value="'.$module->get('infotxt2').'">
<label>URL:</label> <input type="Text" name="newinfolink2" size="50" maxlength="100" value="'.$module->get('infolink2').'">';
if (userHasAccess($usrObj->id, 'filefavorites'))
{
echo '<button type=button onClick="javascript:moveFav2Field(\''.$topdir.'\',\'newinfolink2\',\'newinfotxt2\');" >';
echo '<img src="../img/favorit.gif" alt="Favorit übernehmen" ></button>';
}
echo ' </td></tr>';
echo ' <tr><td><label>'.$l->get('module-infolink-3','Info-Link 3:').' </label></td><td><input type="Text" name="newinfotxt3" size="50" maxlength="250" value="'.$module->get('infotxt3').'">
<label>URL:</label> <input type="Text" name="newinfolink3" size="50" maxlength="100" value="'.$module->get('infolink3').'">';
if (userHasAccess($usrObj->id, 'filefavorites'))
{
echo '<button type=button onClick="javascript:moveFav2Field(\''.$topdir.'\',\'newinfolink3\',\'newinfotxt3\');" >';
echo '<img src="../img/favorit.gif" alt="Favorit übernehmen" ></button>';
}
echo ' </td></tr>';
echo ' <tr><td><label>'.$l->get('general-released-colon','Modul freigegeben:').' </label></td><td><input type="Checkbox" name="newreleased" ';
if ($module->get('released')) echo 'checked';
echo '>';
echo '</td></tr>';
echo '<tr><td><label>'.$l->get('general-visibility-colon','Sichtbarkeit:').' </label></td><td>';
displayLookupSelection("visibility", $module->get('visibility'), "newvisibility", $usrObj->langid);
echo '</td></tr>';
echo '</table></fieldset>';
echo '<p><br><input class=cmd type="reset" value="'.$l->get('general-reset',"Zurücksetzen").'">';
echo '<input class=cmd type="Submit" name="doNewModule" value="';
switch ($newMode)
{
case "insert":
case "new":
case "copy":
echo $l->get('general-create','anlegen');
break;
case "edit":
case "update":
echo $l->get('general-save','speichern');
break;
}
echo '"></p>';
print '</form>';
if (userHasAccess($usrObj->id, 'modulegraf') && ($moduleid != 0))
{
echo '<p>';
echo '<input type="Button"
class="cmd"
onClick=\'parent.frames["rechts"].location.href="modulsvgbearbeiten.php?modifyModuleID='.$moduleid.'"\'
value="'.$l->get('edit-module-graphics-button',"Grafikdaten zum Modul bearbeiten").'" >';
echo '</p>';
}
print $l->getTranslationHelperUI();
print '</body>';
print '</html>';
?>