Jump to content

Database Update


hyperdallas

Recommended Posts

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 ->  softver
EPL -> epl
EAL -> eal
Exempt -> Exempt

 

Any help offered would be amazingly appreciated. Thanks

devices.php

Edited by hyperdallas
Link to comment
Share on other sites

That'll work - good point DaveyK.. Thanks mate...

Here is the code.. here are the fields I have added:

softver
epl

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 by hyperdallas
Link to comment
Share on other sites

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 by mac_gyver
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.