Jump to content


Photo

Database Update


  • Please log in to reply
15 replies to this topic

#1 hyperdallas

hyperdallas

    Member

  • Members
  • PipPip
  • 12 posts

Posted 24 March 2013 - 03:55 AM

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

Attached Files


Edited by hyperdallas, 24 March 2013 - 03:58 AM.


#2 awjudd

awjudd

    Advanced Member

  • Gurus
  • 424 posts

Posted 24 March 2013 - 10:35 PM

Post the code in the PHP tags rather than forcing people to download it.

 

~awjudd


The law of everything: Garbage in, Garbage out.

If you don't give us enough information to help you the correct way, the results won't end up being correct.

Posted Image

#3 hyperdallas

hyperdallas

    Member

  • Members
  • PipPip
  • 12 posts

Posted 25 March 2013 - 01:01 AM

I tried, but the forums say its too long :(



#4 haku

haku

    Advanced Member

  • Staff Alumni
  • 6,172 posts

Posted 25 March 2013 - 03:18 AM

Then you are showing too much code. Scale it down to the relevant code for the problem you are facing.



#5 hyperdallas

hyperdallas

    Member

  • Members
  • PipPip
  • 12 posts

Posted 26 March 2013 - 04:25 PM

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.



#6 haku

haku

    Advanced Member

  • Staff Alumni
  • 6,172 posts

Posted 26 March 2013 - 09:35 PM

Did you not write the code?



#7 hyperdallas

hyperdallas

    Member

  • Members
  • PipPip
  • 12 posts

Posted 27 March 2013 - 02:53 AM

Nope.. I have just customised an existing opensource application..

 

OpenDCIM - Open Source Data Center Inventory Management

http://www.opendcim.org


Edited by hyperdallas, 27 March 2013 - 02:54 AM.


#8 DaveyK

DaveyK

    Advanced Member

  • Members
  • PipPipPip
  • 288 posts
  • LocationThe Netherlands

Posted 27 March 2013 - 05:54 AM

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?



#9 awjudd

awjudd

    Advanced Member

  • Gurus
  • 424 posts

Posted 27 March 2013 - 05:59 AM

There should be an "UPDATE" statement somewhere that it hits.

 

~awjudd


The law of everything: Garbage in, Garbage out.

If you don't give us enough information to help you the correct way, the results won't end up being correct.

Posted Image

#10 hyperdallas

hyperdallas

    Member

  • Members
  • PipPip
  • 12 posts

Posted 27 March 2013 - 06:06 AM

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, 27 March 2013 - 06:07 AM.


#11 hyperdallas

hyperdallas

    Member

  • Members
  • PipPip
  • 12 posts

Posted 28 March 2013 - 03:10 AM

anyone got any ideas?



#12 mac_gyver

mac_gyver

    Advanced Member

  • Administrators
  • 2,255 posts

Posted 28 March 2013 - 08:08 AM

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, 28 March 2013 - 08:13 AM.

multi-purpose programming fool and resident naysayer [We try not be negative in replies, but telling someone what they're doing wrong, while staying politically correct, isn't always going to happen.]

#13 hyperdallas

hyperdallas

    Member

  • Members
  • PipPip
  • 12 posts

Posted 29 March 2013 - 12:33 AM

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.



#14 mac_gyver

mac_gyver

    Advanced Member

  • Administrators
  • 2,255 posts

Posted 29 March 2013 - 08:00 AM

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.


multi-purpose programming fool and resident naysayer [We try not be negative in replies, but telling someone what they're doing wrong, while staying politically correct, isn't always going to happen.]

#15 hyperdallas

hyperdallas

    Member

  • Members
  • PipPip
  • 12 posts

Posted 01 April 2013 - 01:59 AM

ok great... could someone help with this?? ^^^ considering im still learning ?



#16 mac_gyver

mac_gyver

    Advanced Member

  • Administrators
  • 2,255 posts

Posted 01 April 2013 - 03:54 AM

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.


multi-purpose programming fool and resident naysayer [We try not be negative in replies, but telling someone what they're doing wrong, while staying politically correct, isn't always going to happen.]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com