Location: PHPKode > projects > Modular Railroad Asset/Meeting Mgmt > fredl-2-1-9-Release/loco/editloco.php
<?php
    require_once('../php/fredlSession.php');
    /****************************************************************
     * FREMO Asset Management
     * Module: editloco.php
     * Description: Add new loco to the database
     *
     * Created: 3/2004, Klaus Killinger
     * 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: editloco.php,v $
     * Revision 1.24  2005/08/26 21:40:51  dirkj
     * Added coupling field.
     *
     * Revision 1.23  2005/07/11 18:47:47  klk32002
     * Init variable locoid. Use only locoid instead of locoid and id.
     *
     * Revision 1.22  2005/06/07 21:53:30  dirkj
     * Added logDebug calls.
     *
     * Revision 1.21  2005/06/01 23:58:57  dirkj
     * Made multilingual.
     *
     * Revision 1.20  2005/05/04 21:36:05  dirkj
     * Fixed call of lang text for community
     *
     * Revision 1.19  2005/04/17 17:21:23  dirkj
     * Lola Work in progress: step 4
     *
     * Revision 1.18.2.3  2005/04/09 22:54:31  dirkj
     * Moved user configuration and defaults to an own table userconfig
     *
     * Revision 1.18.2.2  2005/04/01 22:47:40  dirkj
     * Added default handling for company.
     *
     * Revision 1.18.2.1  2005/03/31 21:49:15  dirkj
     * Work in progress: step 3
     *
     * Revision 1.18  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.17  2005/02/21 10:09:42  dirkj
     * Added backuri navigation for edit cargo/loco.
     *
     * Revision 1.16  2004/11/01 12:35:47  dirkj
     * Modified session handling.
     *
     * Revision 1.15  2004/10/20 18:44:42  dirkj
     * Added visibility column to objects and handling of that to control
     * security aspects.
     *
     * Revision 1.14  2004/09/30 09:23:37  dirkj
     * Increased field size for Betriebsnummer to 20.
     *
     * Revision 1.13  2004/09/25 17:10:17  dirkj
     * Fixed call of addWnfm.
     *
     * Revision 1.12  2004/09/22 21:26:57  dirkj
     * Added default value for company/bahnverwaltung to DB.
     *
     * Revision 1.11  2004/09/19 21:06:43  dirkj
     * Changed Baureihe zu Betriebsnummer.
     * Migrated to use of Loco class.
     *
     * Revision 1.10  2004/08/29 20:42:58  dirkj
     * Readonly fields are not displayed as input elements anymore.
     *
     * Revision 1.9  2004/08/22 16:29:07  dirkj
     * Added mysql_escape_string to make the code more toleran
     *  to special chars.
     *
     * Revision 1.8  2004/07/19 17:17:41  klk32002
     * Added some old and new fields; show specific function title.
     *
     * Revision 1.7  2004/07/13 20:56:28  dirkj
     * Fixed #989384: Added wheeltype (Rad) attribute.
     *
     * Revision 1.6  2004/07/07 21:24:24  dirkj
     * Added released and graflink fields.
     * Fixed a bug when saving changes twice.
     *
     * Revision 1.5  2004/07/06 20:23:42  klk32002
     * Sub title added like "Kopie" to explain the title
     * "Neuer Güterwagen" more detailed.
     *
     * Revision 1.4  2004/07/06 13:34:53  dirkj
     * Added support for  WNFM (What's New For me).
     *
     * Revision 1.3  2004/06/28 13:52:49  dirkj
     * Update log generation.
     *
     * Revision 1.2  2004/06/23 19:09:53  dirkj
     * Layout change.
     *
     * Revision 1.1  2004/06/21 18:40:25  dirkj
     * New loco functions and dialogues.
     * Reduce the number of files to manage locos.
     * Changed loco db-table and introduced lookup table.
     *
     ****************************************************************/
    require_once '../php/sessionhelpers.inc.php';
    require_once '../php/uihelpers.inc.php';
    require_once '../lib/loco.php';
    require_once '../lib/lang.php';
	
    $usrObj=getUserObject();
    $l = new Lang($usrObj->langid, "loco-editloco", "loco,general");

    print "<html>";
    print "<head>";
    print '<link rel="stylesheet" type="text/css" href="../'.$myStyleSheet.'">';
    print "</head>";
    print '<body class=right>';

   $backuri=GET2Var('backuri');
   $mode=$_GET['mode'];
   $loco = new Loco();

   $idValuePairs = new idValuePairList("SELECT communityid as id, communityname as value FROM community");


   switch ($mode)
   {
	   case 'edit':
      		$locoid=$_GET['locoid'];
      		$loco->dbRead($locoid);
		    $communityAttrib = new n2mAttribute("community_loco", "locoid", $locoid, "communityid", $idValuePairs);
		    $communityAttrib->updateSelectedFromDB();
	 	    print '<h1>'.$l->get('loco-editloco-edit-title', 'Triebfahrzeug ändern').'</h1>';
         	$newMode="update"; 
		break;

	   case 'copy':
      		$locoid=$_GET['locoid'];
      		$loco->dbRead($locoid);
		    $communityAttrib = new n2mAttribute("community_loco", "locoid", $locoid, "communityid", $idValuePairs);
		    $communityAttrib->updateSelectedFromDB();
	 	    print '<h1>'.$l->get('loco-editloco-copy-title', 'Triebfahrzeug kopieren').'</h1>';
         	$newMode="insert";
	 	    $loco->set('locoid',0);
	 	    $loco->set('ownerid',$usrObj->id);
		break;

	   case 'new':
	   	    $locoid=null; //init variable, otherwise not defined when calling LogDebug
		    $loco->set('ownerid',$usrObj->id);
	        $loco->set('company',$usrObj->getConfig("Defaults", "DefaultCompany"));   // Default value for company/bahnverwaltung
		    $communityAttrib = new n2mAttribute("community_loco", "locoid", null, "communityid", $idValuePairs);

		    $newMode="insert";
	 	    print '<h1>'.$l->get('loco-editloco-new-title', 'Triebfahrzeug neu anlegen').'</h1>';
		break;

	   case 'insert':
		    $loco->getFromPOST('new');
	      	$loco->dbWrite();
		    $locoid = $loco->get('locoid');
		    $communityAttrib = new n2mAttribute("community_loco", "locoid", $locoid, "communityid", $idValuePairs);
		    $communityAttrib->updateSelectedFromPOST($_POST);
		    $communityAttrib->writeToDB();
			print sprintf($l->get('loco-added-msg','Triebfahrzeug mit Tfz-ID %d angelegt.'), $locoid);
	      	logAudit("editloco.php: Tfz " . $loco->get('baureihe') . " (id=$locoid) angelegt.");
	      	addWnfm($usrObj->id, "new loco", 
	                'Tfz '.$loco->get('baureihe').' (DCC '.$loco->get('dccadr').', id='.$locoid.') angelegt.');
	   	    $newMode="update";
		    // specify title:
	 	    print '<h1>'.$l->get('loco-editloco-edit-title', 'Triebfahrzeug ändern').'</h1>';
		break;

	   case 'update':
		    $loco->getFromPOST('new');
		    $locoid = $loco->get('locoid');
		    $communityAttrib = new n2mAttribute("community_loco", "locoid", $locoid, "communityid", $idValuePairs);
		    $communityAttrib->updateSelectedFromPOST($_POST);
	        $loco->dbWrite();
		    $communityAttrib->writeToDB();
            // print '<p>Tfz ' . $loco->get('baureihe') . ' (id='.$locoid.') geändert.</p>';
			print sprintf($l->get('loco-chanced-msg','Triebfahrzeug mit Tfz-ID %d geändert.'), $locoid);
	        logAudit("editloco.php: Tfz (id=$locoid) " . $loco->get('baureihe') . " geändert.");
	   	    $newMode="update";
		    // specify title:
	 	    print '<h1>'.$l->get('loco-editloco-edit-title', 'Triebfahrzeug ändern').'</h1>';
		break;

	default:
		    echo "<p>ERROR: Unknown mode -$mode-</p>";
		break;
   }

   logDebug("loco-edit mode=$mode | locoid=$locoid | backuri=$backuri");

   echo "<form action='editloco.php?mode=$newMode&backuri=$backuri' method='post'>";
   echo "<table>";

// prepare to display data:
echo  '<tr><td></td><td><input type="Hidden" name="newlocoid" size="5" maxlength="5" value="'.$loco->get('locoid').'" readonly></td>';
echo '<input type="hidden" name="newownerid" value="'.$loco->get('ownerid').'">';

echo '</tr>';
echo  '<tr><td><label>'.$l->get('loco-type','Typ:').' </label></td><td>';
displayLookupSelection("locotype", $loco->get('type'), "newtype", $usrObj->langid);
echo  '</td></tr>';
echo ' <tr><td><label>'.$l->get('loco-number','Betriebsnummer:').' </label></td><td><input type="Text" name="newbaureihe" size="20" maxlength="20" value="'.$loco->get('baureihe').'"></td></tr>
       <tr><td><label>'.$l->get('loco-since','Einsatz von:').' </label></td><td><input type="Text" name="neweinsatzvon" size="4" maxlength="4" value="'.$loco->get('einsatzvon').'"></td></tr>
       <tr><td><label>'.$l->get('loco-until','Einsatz bis:').' </label></td><td><input type="Text" name="neweinsatzbis" size="4" maxlength="4" value="'.$loco->get('einsatzbis').'"></td></tr>
       <tr><td><label>'.$l->get('loco-dcc-adress','DCC-Adresse:').' </label></td><td><input type="Text" name="newdccadr" size="4" maxlength="4" value="'.$loco->get('dccadr').'"></td></tr>';
echo ' <tr><td><label>'.$l->get('loco-decoder-type','Decodertyp:').' </label></td><td><input type="Text" name="newdecodertype" size="20" maxlength="50" value="'.$loco->get('decodertype').'"></td></tr>
	   <tr><td><label>'.$l->get('loco-dcc-description','DCC-Beschreibung:').' </label></td><td><input type="Text" name="newdccdescription" size="50" maxlength="100" value="'.$loco->get('dccdescription').'"></td></tr>';   

// Show Wheeltype Field
echo  '<tr><td><label>'.$l->get('general-wheel-colon','Rad:').' </label></td><td>';
displayLookupSelection("wheeltype", $loco->get('rad'), "newrad", $usrObj->langid);
echo  '</td></tr>';

// Show Coupling Field
echo  '<tr><td><label>'.$l->get('general-coupling-colon','Kupplung:').' </label></td><td>';
displayLookupSelection("coupling", $loco->get('coupling'), "newcoupling", $usrObj->langid);
echo  '</td></tr>';

// Show Description Field
echo  '<tr><td><label>'.$l->get('general-description-colon','Beschreibung:').' </label></td><td><input type="Text" name="newdescription" size="50" maxlength="250" value="'.$loco->get('description').'"></td></tr>';
echo  '<tr><td><label>'.$l->get('general-vmax-colon','Vmax (km/h):').' </label></td><td><input type="Text" name="newvmax" size="5" maxlength="4" value="'.$loco->get('vmax').'"></td></tr>'; 
echo  '<tr><td><label>'.$l->get('loco-usedfor','Einsatz:').' </label></td><td><input type="checkbox" name="newpassenger" size="5" maxlength="20" ';
if ($loco->get('passenger')) { echo ' checked="checked"'; }
echo  '>'.$l->get('loco-passenger-train','Personenzug').'</input></td></tr>';      
echo  '<tr><td></td><td><input type="checkbox" name="newcargo" size="5" maxlength="20" ';
if ($loco->get('cargo')) { echo ' checked="checked"'; }
echo  '>'.$l->get('loco-cargo-train','Güterzug').'</input></td></tr>';      
echo  '<tr><td></td><td><input type="checkbox" name="newshunter" size="5" maxlength="20" ';
if ($loco->get('shunter')) { echo ' checked="checked"'; }
echo  '>'.$l->get('loco-shunter','Rangierlok').'</input></td></tr>';      
echo  '<tr><td><label>'.$l->get('general-company-colon','Gesellschaft:').' </label></td><td><input type="Text" name="newcompany" size="5" maxlength="20" value="'.$loco->get('company').'"></td></tr>';      
echo ' <tr><td><label>'.$l->get('loco-locoedit-release','Tfz freigegeben:').' </label></td><td><input type="Checkbox" name="newreleased" ';
if ($loco->get('released')) echo 'checked';
echo '>';
echo '</td></tr>';

echo '<tr><td valign=top>'.$l->get('community-colon','Gruppenzugehörigkeit').'</td>';
echo '<td>';
print $communityAttrib->getUI();
echo '</td></tr>';

echo '<tr><td><label>'.$l->get('general-visibility-colon','Sichtbarkeit:').' </label></td><td>';
displayLookupSelection("visibility", $loco->get('visibility'), "newvisibility", $usrObj->langid);
echo '</td></tr>';

echo '<tr><td>';
echo '<input type="hidden" name="newgraflink" value="'.$loco->get('graflink').'">';
echo '</td></tr>';

echo '<tr><td><input class=cmd type="reset" value="'.$l->get('general-reset','Zurücksetzen').'"></td><td>';
echo '<input class=cmd type="Submit" name="doNewLoco" 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 '"></td></tr>';
print '</table>';
print '</form>';

   if ($backuri != "")
   {
      echo '<input type="Button" 
                   class="cmd" 
	           onClick=\'parent.frames["rechts"].location.href="'.$backuri.'"\' 
	           value="'.$l->get('general-back-button','Zurück').'" >';
   }

   print $l->getTranslationHelperUI();
   print "</body></html>";

?>
Return current item: Modular Railroad Asset/Meeting Mgmt