Private GIT

Skip to content
Snippets Groups Projects
Unverified Commit c3d33be5 authored by Miha Petkovsek's avatar Miha Petkovsek Committed by GitHub
Browse files

Merge pull request #2262 from Satisfaption/patch-3

add custom fields to VRF in import / export 
parents e4572399 5a10e99c
Branches
No related tags found
No related merge requests found
......@@ -10,10 +10,26 @@ require_once( dirname(__FILE__) . '/../../../functions/functions.php' );
# initialize user object
$Database = new Database_PDO;
$User = new User ($Database);
$Tools = new Tools ($Database);
# verify that user is logged in
$User->check_user_session();
# get all custom fields
$custom_fields = $Tools->fetch_custom_fields('vrf');
# prepare HTML variables
$custom_fields_names = "";
$custom_fields_boxes = "";
if(sizeof($custom_fields) > 0) {
foreach($custom_fields as $myField) {
//change spaces to "___" so it can be used as element id
$myField['nameTemp'] = str_replace(" ", "___", $myField['name']);
$custom_fields_names.= " <th>$myField[name]</th>";
$custom_fields_boxes.= " <td><input type='checkbox' name='$myField[nameTemp]' checked> </td>";
}
}
?>
<!-- header -->
......@@ -34,12 +50,14 @@ print " <tr>";
print " <th>"._('Name')."</th>";
print " <th>"._('RD')."</th>";
print " <th>"._('Description')."</th>";
print $custom_fields_names;
print " </tr>";
print " <tr>";
print " <td><input type='checkbox' name='name' checked title='"._('Mandatory')."'></td>";
print " <td><input type='checkbox' name='rd' checked> </td>";
print " <td><input type='checkbox' name='description' checked> </td>";
print $custom_fields_boxes;
print " </tr>";
print '</table>';
......
......@@ -17,6 +17,7 @@ $Database = new Database_PDO;
$Result = new Result;
$User = new User ($Database);
$Admin = new Admin ($Database);
$Tools = new Tools ($Database);
# verify that user is logged in
$User->check_user_session();
......@@ -25,6 +26,9 @@ $User->check_user_session();
$all_vrfs = $Admin->fetch_all_objects("vrf", "vrfId");
if (!$all_vrfs) { $all_vrfs = array(); }
# get all custom fields
$custom_fields = $Tools->fetch_custom_fields('vrf');
# Create a workbook
$today = date("Ymd");
$filename = $today."_phpipam_VRF_export.xls";
......@@ -63,6 +67,18 @@ if( (isset($_GET['description'])) && ($_GET['description'] == "on") ) {
$curColumn++;
}
//custom fields
if(sizeof($custom_fields) > 0) {
foreach($custom_fields as $myField) {
//set temp name - replace space with three ___
$myField['nameTemp'] = str_replace(" ", "___", $myField['name']);
if( (isset($_GET[$myField['nameTemp']])) && ($_GET[$myField['nameTemp']] == "on") ) {
$worksheet->write($curRow, $curColumn, $myField['name'] ,$format_header);
$curColumn++;
}
}
}
$curRow++;
//write all VRF entries
......@@ -86,6 +102,18 @@ foreach ($all_vrfs as $vrf) {
$curColumn++;
}
//custom fields, per VLAN
if(sizeof($custom_fields) > 0) {
foreach($custom_fields as $myField) {
//set temp name - replace space with three ___
$myField['nameTemp'] = str_replace(" ", "___", $myField['name']);
if( (isset($_GET[$myField['nameTemp']])) && ($_GET[$myField['nameTemp']] == "on") ) {
$worksheet->write($curRow, $curColumn, $vlan[$myField['name']], $format_text);
$curColumn++;
}
}
}
$curRow++;
}
......
......@@ -15,6 +15,9 @@ if (!isset($Admin)) { $Admin = new Admin ($Database); }
# verify that user is logged in, to guard against direct access of page and possible exploits
$User->check_user_session();
# read again the custom fields, if any
if (!isset($custom_fields)) { $custom_fields = $Tools->fetch_custom_fields("vrf"); }
# Load existing data
$all_vrfs = $Admin->fetch_all_objects("vrf", "vrfId");
if (!$all_vrfs) { $all_vrfs = array(); }
......@@ -54,6 +57,15 @@ foreach ($data as &$cdata) {
if ($cdata['name'] != $edata[$cdata['rd']]['name']) { $msg.= "VRF name will be updated."; $action = "edit"; }
if ($cdata['description'] != $edata[$cdata['rd']]['description']) { $msg.= "VRF description will be updated."; $action = "edit"; }
# Check if the values of the custom fields have changed
if(sizeof($custom_fields) > 0) {
foreach($custom_fields as $myField) {
if ($cdata[$myField['name']] != $edata[$cdata['rd']][$myField['name']]) {
$msg.= $myField['name']." will be updated."; $action = "edit";
}
}
}
if ($action == "skip") {
$msg.= "Duplicate, will skip.";
}
......@@ -66,11 +78,9 @@ foreach ($data as &$cdata) {
$cdata['action'] = $action;
$counters[$action]++;
$rows.="<tr class='".$colors[$action]."'><td><i class='fa ".$icons[$action]."' rel='tooltip' data-placement='bottom' title='"._($msg)."'></i></td>
<td>".$cdata['name']."</td>
<td>".$cdata['rd']."</td>
<td>".$cdata['description']."</td>
<td>"._($msg)."</td></tr>";
$rows.="<tr class='".$colors[$action]."'><td><i class='fa ".$icons[$action]."' rel='tooltip' data-placement='bottom' title='"._($msg)."'></i></td>";
foreach ($expfields as $cfield) { $rows.= "<td>".$cdata[$cfield]."</td>"; }
$rows.= "<td>"._($cdata['msg'])."</td></tr>";
}
......
......@@ -50,6 +50,10 @@ $custom_fields = $Tools->fetch_custom_fields("vrf");
if(sizeof($custom_fields) > 0) {
$res[] = $custom_fields;
foreach($custom_fields as $myField) {
# add field to required fields if needed
if ($myField['Null'] == "NO") { $reqfields[] = $myField['name']; }
# mark required fields with *
$msgr = in_array($myField['name'],$reqfields) ? "*" : "";
$tpl_field_names.= "<th>". $myField['name'] ."</th>";
$tpl_field_types.= "<td><small>". wordwrap($myField['type'],18,"<br>\n",true) ."</small></td>";
$expfields[] = $myField['name'];
......
......@@ -40,6 +40,13 @@ foreach ($data as &$cdata) {
"rd"=>$cdata['rd'],
"description"=>$cdata['description']
);
# add custom fields
if(sizeof($custom_fields) > 0) {
foreach($custom_fields as $myField) {
if(isset($cdata[$myField['name']])) { $values[$myField['name']] = $cdata[$myField['name']]; }
}
}
# update
$cdata['result'] = $Admin->object_modify("vrf", $cdata['action'], "vrfId", $values);
......@@ -54,6 +61,7 @@ foreach ($data as &$cdata) {
<td>".$cdata['name']."</td>
<td>".$cdata['rd']."</td>
<td>".$cdata['description']."</td>
".$cfieldtds."
<td>"._($msg)."</td></tr>";
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment