hyperdallas Posted March 24, 2013 Share Posted March 24, 2013 (edited) I have taken an existing form from an open source application im customising and have added a few extra variables that I am trying to have the script include when updating the form. Unfortunately I cant get it updating the new fields no matter how hard I try.My code is attached. The New Fields added are:Form Name Database field name Software Version -> softverEPL -> eplEAL -> ealExempt -> Exempt Any help offered would be amazingly appreciated. Thanks devices.php Edited March 24, 2013 by hyperdallas Quote Link to comment Share on other sites More sharing options...
awjudd Posted March 25, 2013 Share Posted March 25, 2013 Post the code in the PHP tags rather than forcing people to download it. ~awjudd Quote Link to comment Share on other sites More sharing options...
hyperdallas Posted March 25, 2013 Author Share Posted March 25, 2013 I tried, but the forums say its too long Quote Link to comment Share on other sites More sharing options...
haku Posted March 25, 2013 Share Posted March 25, 2013 Then you are showing too much code. Scale it down to the relevant code for the problem you are facing. Quote Link to comment Share on other sites More sharing options...
hyperdallas Posted March 26, 2013 Author Share Posted March 26, 2013 Thats exactly the problem. since i am still learning, i cant give you the snippet because i dont know where the functions are being performed. Quote Link to comment Share on other sites More sharing options...
haku Posted March 27, 2013 Share Posted March 27, 2013 Did you not write the code? Quote Link to comment Share on other sites More sharing options...
hyperdallas Posted March 27, 2013 Author Share Posted March 27, 2013 (edited) Nope.. I have just customised an existing opensource application.. OpenDCIM - Open Source Data Center Inventory Management http://www.opendcim.org Edited March 27, 2013 by hyperdallas Quote Link to comment Share on other sites More sharing options...
DaveyK Posted March 27, 2013 Share Posted March 27, 2013 You state that "you cant get it to update the new field no matter how hard you try". Surely can find the code you have tried so hard on? Quote Link to comment Share on other sites More sharing options...
awjudd Posted March 27, 2013 Share Posted March 27, 2013 There should be an "UPDATE" statement somewhere that it hits. ~awjudd Quote Link to comment Share on other sites More sharing options...
hyperdallas Posted March 27, 2013 Author Share Posted March 27, 2013 (edited) That'll work - good point DaveyK.. Thanks mate...Here is the code.. here are the fields I have added:softverepl eal exe if(isset($_REQUEST['action'])){ if($user->WriteAccess&&(($dev->DeviceID >0)&&($_REQUEST['action']=='Update'))){ $dev->Label=$_REQUEST['label']; $dev->SerialNo=$_REQUEST['serialno']; $dev->AssetTag=$_REQUEST['assettag']; $dev->Owner=$_REQUEST['owner']; $dev->EscalationTimeID=$_REQUEST['escalationtimeid']; $dev->EscalationID=$_REQUEST['escalationid']; $dev->PrimaryContact=$_REQUEST['primarycontact']; $dev->Cabinet=$_REQUEST['cabinetid']; $dev->Position=$_REQUEST['position']; $dev->Height=$_REQUEST['height']; $dev->TemplateID=$_REQUEST['templateid']; $dev->DeviceType=$_REQUEST['devicetype']; $dev->MfgDate=date('Y-m-d',strtotime($_REQUEST['mfgdate'])); $dev->InstallDate=date('Y-m-d',strtotime($_REQUEST['installdate'])); $dev->WarrantyCo=$_REQUEST['warrantyco']; $dev->WarrantyExpire=date('Y-m-d',strtotime($_REQUEST['warrantyexpire'])); // All of the values below here are optional based on the type of device being dealt with $dev->ChassisSlots=(isset($_REQUEST['chassisslots']))?$_REQUEST['chassisslots']:0; $dev->RearChassisSlots=(isset($_REQUEST['rearchassisslots']))?$_REQUEST['rearchassisslots']:0; $dev->Ports=(isset($_REQUEST['ports']))?$_REQUEST['ports']:""; $dev->PowerSupplyCount=(isset($_REQUEST['powersupplycount']))?$_REQUEST['powersupplycount']:""; $dev->ParentDevice=(isset($_REQUEST['parentdevice']))?$_REQUEST['parentdevice']:""; $dev->PrimaryIP=(isset($_REQUEST['primaryip']))?$_REQUEST['primaryip']:""; $dev->SNMPCommunity=(isset($_REQUEST['snmpcommunity']))?$_REQUEST['snmpcommunity']:""; $dev->ESX=(isset($_REQUEST['esx']))?$_REQUEST['esx']:0; $dev->Reservation=(isset($_REQUEST['reservation']))?$_REQUEST['reservation']:0; $dev->NominalWatts=$_REQUEST['nominalwatts']; $dev->SoftVer=$_REQUEST['softver']; $dev->EPL=$_REQUEST['epl']; $dev->EAL=$_REQUEST['eal']; $dev->EXEMPT=$_REQUEST['exe']; if(($dev->TemplateID >0)&&(intval($dev->NominalWatts==0))){$dev->UpdateWattageFromTemplate($facDB);} if($dev->Cabinet <0){ $dev->MoveToStorage($facDB); }else{ $dev->UpdateDevice($facDB); } }elseif($user->WriteAccess&&($_REQUEST['action']=='Create')){ $dev->Label=$_REQUEST['label']; $dev->SerialNo=$_REQUEST['serialno']; $dev->AssetTag=$_REQUEST['assettag']; $dev->Owner=$_REQUEST['owner']; $dev->EscalationTimeID=$_REQUEST['escalationtimeid']; $dev->EscalationID=$_REQUEST['escalationid']; $dev->PrimaryContact=$_REQUEST['primarycontact']; $dev->Cabinet=$_REQUEST['cabinetid']; $dev->Position=$_REQUEST['position']; $dev->Height=$_REQUEST['height']; $dev->Ports=$_REQUEST['ports']; $dev->TemplateID=$_REQUEST['templateid']; $dev->DeviceType=$_REQUEST['devicetype']; $dev->MfgDate=date('Y-m-d',strtotime($_REQUEST['mfgdate'])); $dev->InstallDate=date('Y-m-d',strtotime($_REQUEST['installdate'])); $dev->WarrantyCo=$_REQUEST['warrantyco']; $dev->WarrantyExpire=date('Y-m-d',strtotime($_REQUEST['warrantyexpire'])); $dev->Notes=$_REQUEST['notes']; $dev->SoftVer=$_REQUEST['softver']; $dev->EPL=$_REQUEST['epl']; $dev->EAL=$_REQUEST['eal']; $dev->Exempt=$_REQUEST['exe']; // All of the values below here are optional based on the type of device being dealt with $dev->ChassisSlots=(isset($_REQUEST['chassisslots']))?$_REQUEST['chassisslots']:0; $dev->RearChassisSlots=(isset($_REQUEST['rearchassisslots']))?$_REQUEST['rearchassisslots']:0; $dev->Ports=(isset($_REQUEST['ports']))?$_REQUEST['ports']:""; $dev->PowerSupplyCount=(isset($_REQUEST['powersupplycount']))?$_REQUEST['powersupplycount']:""; $dev->ParentDevice=(isset($_REQUEST['parentdevice']))?$_REQUEST['parentdevice']:""; $dev->PrimaryIP=(isset($_REQUEST['primaryip']))?$_REQUEST['primaryip']:""; $dev->SNMPCommunity=(isset($_REQUEST['snmpcommunity']))?$_REQUEST['snmpcommunity']:""; $dev->ESX=(isset($_REQUEST['esx']))?$_REQUEST['esx']:0; $dev->Reservation=(isset($_REQUEST['reservation']))?$_REQUEST['reservation']:0; $dev->CreateDevice($facDB); }elseif($user->DeleteAccess&&($_REQUEST['action']=='Delete')){ $dev->GetDevice($facDB); $dev->DeleteDevice($facDB); header('Location: '.redirect("cabnavigator.php?cabinetid=$dev->Cabinet")); exit; }elseif($user->WriteAccess&&$_REQUEST['action']=='child'){ if(isset($_REQUEST['parentdevice'])){ $dev->DeviceID=null; $dev->ParentDevice=$_REQUEST["parentdevice"]; } // sets install date to today when a new device is being created $dev->InstallDate=date("m/d/Y"); } } // Finished updating devices or creating them. Refresh the object with data from the DB $dev->GetDevice($facDB); Edited March 27, 2013 by hyperdallas Quote Link to comment Share on other sites More sharing options...
hyperdallas Posted March 28, 2013 Author Share Posted March 28, 2013 anyone got any ideas? Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted March 28, 2013 Share Posted March 28, 2013 (edited) your question is about the update not working, but does the create work? if create works, that means that you modified the code in the device() class CreateDevice method to deal with the new fields. you would need to also modify the code in the UpdateDevice method too. Edited March 28, 2013 by mac_gyver Quote Link to comment Share on other sites More sharing options...
hyperdallas Posted March 29, 2013 Author Share Posted March 29, 2013 create works only for the original fields on the form and not the new ones i added. when i hit update, it wipes the data entered into the new fields and not saves it - everything else it saves. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted March 29, 2013 Share Posted March 29, 2013 adding more fields to this code is more than just adding columns to the database table, adding input fields to the form, and adding statements to the code in devices.php. all the code in the device class must be modified to operate on the additional fields. you need to trace through the execution of the code all the way to the query statements. i have looked at the device class code some and it's too bad the author didn't make his code general purpose so that all he or you would need to do to add fields is to add them to the database table and define them in a configuration file. the author should have used __set()/__get() magic methods to allow all the classes to operate on any arbitrary list of properties and to have defined a list of the fields/properties and their data type in a configuration file. all the code would have used this definition instead of hard coding everything and all you would have needed to do to accomplish your task is to add your new fields to the database table and to the definition in a configuration file. Quote Link to comment Share on other sites More sharing options...
hyperdallas Posted April 1, 2013 Author Share Posted April 1, 2013 ok great... could someone help with this?? ^^^ considering im still learning ? Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted April 1, 2013 Share Posted April 1, 2013 what have you tried? there's a point where helping becomes doing and that isn't likely to happen for thousands of lines of code (the device class is just over 1000 lines of code, which could have been about 500 lines if the author had programmed smarter instead of programming harder) in a 3rd party script. you are the only one here who wants this application to have the extra fields added to it. it's up to you to attempt to do the work needed. i will give a hint: the device() class is defined in the assets.inc.php file. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.