Ad Widget

Collapse

PATCH: forms.inc.php not able to add links on sysmaps

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • adam.vollrath
    Member
    • Apr 2006
    • 31

    #1

    PATCH: forms.inc.php not able to add links on sysmaps

    See threads:


    and


    I also had this problem, and I'm suprised no one has patched it yet, since it disables such a neat feature. Maybe not everyone is having this problem? I'm using
    PHP 5.1.2 (cli) (built: Feb 28 2006 06:21:15)
    Fedora Core 5
    and Zabbix 1.1beta9
    for what that's worth.

    Anyway, I took a couple hours and fixed the problem, it's in the insert_map_link_form() function in ./include/forms.inc.php

    The author here attempted to reuse some form elements by renaming them, or something. Anyway, it didn't quite work, giving me bad forms that submitted GET requests with duplicate selementid2, type_on, and color_on fields, while ommitting the selementid1, type_off, and color_off fields, because they were not present on the generated form.

    I've modified the code and attached a patch, here's the new parts of insert_map_link_form() for beta9:

    The prep:
    Code:
    /* START comboboxes preparations */
    		$cmbElements = new CComboBox("selementid1",$selementid1);
    		$cmbElements2 = new CComboBox("selementid2",$selementid2);
    
    		$db_selements = DBselect("select selementid,label,elementid,elementtype from sysmaps_elements".
    			" where sysmapid=".$_REQUEST["sysmapid"]);
    
    		while($db_selement = DBfetch($db_selements))
    		{
    			$label = $db_selement["label"];
    			if($db_selement["elementtype"] == SYSMAP_ELEMENT_TYPE_HOST)
    			{
    				$db_host = get_host_by_hostid($db_selement["elementid"]);
    				$label .= ":".$db_host["host"];
    			}
    			elseif($db_selement["elementtype"] == SYSMAP_ELEMENT_TYPE_MAP)
    			{
    				$db_map = get_sysmap_by_sysmapid($db_selement["elementid"]);
    				$label .= ":".$db_map["name"];
    			}
    			elseif($db_selement["elementtype"] == SYSMAP_ELEMENT_TYPE_IMAGE)
    			{
    				if($db_selement["elementid"]>0)
    				{
    					$label .= ":".expand_trigger_description($db_selement["elementid"]);
    				}
    			}
    			$cmbElements->AddItem($db_selement["selementid"],$label);
    			$cmbElements2->AddItem($db_selement["selementid"],$label);
    		}
    
    		$cmbType = new CComboBox("drawtype_off",$drawtype_off);
    		$cmbType->AddItem(0,get_drawtype_description(0));
    		$cmbType->AddItem(1,get_drawtype_description(1));
    		$cmbType->AddItem(2,get_drawtype_description(2));
    		$cmbType->AddItem(3,get_drawtype_description(3));
    		$cmbType->AddItem(4,get_drawtype_description(4));
    
    		$cmbType2 = new CComboBox("drawtype_on",$drawtype_on);
    		$cmbType2->AddItem(0,get_drawtype_description(0));
    		$cmbType2->AddItem(1,get_drawtype_description(1));
    		$cmbType2->AddItem(2,get_drawtype_description(2));
    		$cmbType2->AddItem(3,get_drawtype_description(3));
    		$cmbType2->AddItem(4,get_drawtype_description(4));
    
    		$cmbColor = new CComboBox("color_off",$color_off);
    		$cmbColor->AddItem('Black',"Black");
    		$cmbColor->AddItem('Blue',"Blue");
    		$cmbColor->AddItem('Cyan',"Cyan");
    		$cmbColor->AddItem('Dark Blue',"Dark Blue");
    		$cmbColor->AddItem('Dark Green',"Dark Green");
    		$cmbColor->AddItem('Dark Red',"Dark Red");
    		$cmbColor->AddItem('Dark Yellow',"Dark Yellow");
    		$cmbColor->AddItem('Green',"Green");
    		$cmbColor->AddItem('Red',"Red");
    		$cmbColor->AddItem('White',"White");
    		$cmbColor->AddItem('Yellow',"Yellow");
    
    		$cmbColor2 = new CComboBox("color_on",$color_on);
    		$cmbColor2->AddItem('Black',"Black");
    		$cmbColor2->AddItem('Blue',"Blue");
    		$cmbColor2->AddItem('Cyan',"Cyan");
    		$cmbColor2->AddItem('Dark Blue',"Dark Blue");
    		$cmbColor2->AddItem('Dark Green',"Dark Green");
    		$cmbColor2->AddItem('Dark Red',"Dark Red");
    		$cmbColor2->AddItem('Dark Yellow',"Dark Yellow");
    		$cmbColor2->AddItem('Green',"Green");
    		$cmbColor2->AddItem('Red',"Red");
    		$cmbColor2->AddItem('White',"White");
    		$cmbColor2->AddItem('Yellow',"Yellow");
    And the followup:
    Code:
    /* END preparation */
    
    		$frmCnct->AddRow("Element 1",$cmbElements);
    
    //		$cmbElements->SetName("selementid2");	// rename without recreation
    //		$cmbElements->SetValue($selementid2);	// rename without recreation
    
    		$frmCnct->AddRow("Element 2",$cmbElements2);
    Code:
    		$frmCnct->AddRow("Type (OFF)",$cmbType);
    
    		$frmCnct->AddRow("Color (OFF)",$cmbColor);
    
    //		$cmbType->SetName("drawtype_on"); 	// rename without recreation
    //		$cmbType->SetValue($drawtype_on);	// rename without recreation
    		$frmCnct->AddRow("Type (ON)",$cmbType2);
    
    //		$cmbColor->SetName("color_on");		// rename without recreation
    //		$cmbColor->SetValue($color_on);		// rename without recreation
    		$frmCnct->AddRow("Color (ON)",$cmbColor2);
    We're planning on using Zabbix for our business of 50ish employees. Thank you for an excellent program and keep up the good work.
    Attached Files
  • jean
    Member
    • Apr 2006
    • 85

    #2
    Don't understand your patch

    Hello,

    Could you post your full file forms.inc.php please ?

    Thank you in advanced

    Comment

    • adam.vollrath
      Member
      • Apr 2006
      • 31

      #3
      This forms.inc.php is zipped and for 1.1beta9.

      The changes I've made are in the last function, insert_map_link_form().
      Attached Files

      Comment

      • jean
        Member
        • Apr 2006
        • 85

        #4
        Thank you !

        Comment

        • mfinn999
          Junior Member
          • May 2006
          • 4

          #5
          different error after updating forms.inc.php

          I added the patched file, and now I get a different error:

          [ERROR:Cannot add link]

          SQL error: Unknown column 'selementid1' in 'field list'
          Query: insert into sysmaps_links (sysmapid,selementid1,selementid2,triggerid,drawty pe_off,color_off,drawtype_on,color_on) values (3,5,4,10038,0,'Yellow',0,'Blue')

          I'm guessing there's a fairly easy solution, but I'm no SQL wizard. Can anyone help me out?

          Comment

          • adam.vollrath
            Member
            • Apr 2006
            • 31

            #6
            Are you using beta9? If so, try replacing the whole file with the contents of the .zip above. If you're not using beta9, or have not run all the incremental MySQL database upgrade scripts, you may have a table that is incomplete

            Try logging into SQL from the command line and running "select * from sysmaps_links;" to see what columns the table contains. Also try pasting in the insert command you mentioned and see what happens.

            Also, there's a stray space in the query you pasted above, in drawtype_off. I assume that's a typo?
            Last edited by adam.vollrath; 09-05-2006, 17:56. Reason: typos

            Comment

            • mfinn999
              Junior Member
              • May 2006
              • 4

              #7
              Originally posted by adam.vollrath
              Are you using beta9? If so, try replacing the whole file with the contents of the .zip above. If you're not using beta9, or have not run all the incremental MySQL database upgrade scripts, you may have a table that is incomplete...
              I am running beta9. I did replace the entire forms.inc.php file with the contents of the zip, makeing sure permissions were correct and all. I did not see anything about incremental MySQL database scripts. Where are those located?

              Comment

              • adam.vollrath
                Member
                • Apr 2006
                • 31

                #8
                When I said "incremental MySQL database scripts", I was referring to upgrading from one version to the next, but I guess that doesn't apply to you.

                Try getting into your mySQL shell and executing that query that Zabbix tried to run:

                Code:
                [root@localdomain ~]# mysql -p
                
                mysql> insert into sysmaps_links (sysmapid,selementid1,selementid2,triggerid,drawtype_off,color_off,drawtype_on,color_on) values (3,5,4,10038,0,'Yellow',0,'Blue')

                Comment

                Working...