/** * renderUserWidget * * @param entry dashboardUserWidget object * @throws PDOException * @return none */ public function renderUserWidget(dashboardUserWidget $entry) { try { $rtn = array(); $rtn['type'] = 'html'; require_once dirname(realpath(__FILE__)) . '/../deviceGroup.php'; require_once dirname(realpath(__FILE__)) . '/../deviceEntry.php'; // get group name from id $prms = $entry->params; $grp = new deviceGroup($this->db); $grp->getById($prms['group_id']); if ($grp) { $counts = array(); $counts['ok'] = 0; $counts['warn'] = 0; $counts['critical'] = 0; $rtn['value'] = '<div style="font-weight: bold; font-size: larger; text-align: center;">' . $grp->name . ' summary</div/>'; // get status for children foreach ($grp->children() as $c) { $dev = new deviceEntry($this->db); $dev->getById($c); if ($dev->id) { $status = $dev->maxStatus(); if (array_key_exists($status, $counts)) { $counts[$status]++; } else { $counts[$status] = 1; } } } // add to output $rtn['value'] .= '<span style="font-align: left; font-weight: bold;">ok</span><span style="float: right;">' . $counts['ok'] . '</span><br/>' . "\n"; $rtn['value'] .= '<span style="font-align: left; font-weight: bold; color: #b3511d;">warn</span><span style="float: right; color: #b3511d;">' . $counts['warn'] . '</span><br/>' . "\n"; $rtn['value'] .= '<span style="font-align: left; font-weight: bold; color: #a62434;">critical</span><span style="float: right; color: #a62434;">' . $counts['critical'] . '</span><br/>' . "\n"; } else { $rtn['value'] = '<center>unknown group id</center>'; } } catch (PDOException $e) { throw $e; } return $rtn; }
/** * renderUserWidget * * @param entry dashboardUserWidget object * @throws PDOException * @return none */ public function renderUserWidget(dashboardUserWidget $entry) { global $panoptes_current_user; try { $rtn = array(); $rtn['type'] = 'js'; $rtn['value'] = ''; require_once dirname(realpath(__FILE__)) . '/../deviceGroup.php'; require_once dirname(realpath(__FILE__)) . '/../deviceEntry.php'; require_once dirname(realpath(__FILE__)) . '/../userEntry.php'; require_once dirname(realpath(__FILE__)) . '/../userPrefs.php'; // get group name from id $prms = $entry->params; $grp = new deviceGroup($this->db); $grp->getById($prms['group_id']); if ($grp) { $counts = array(); $counts['ok'] = 0; $counts['warn'] = 0; $counts['critical'] = 0; // get status for children foreach ($grp->children() as $c) { $dev = new deviceEntry($this->db); $dev->getById($c); if ($dev->id) { $status = $dev->maxStatus(); if (array_key_exists($status, $counts)) { $counts[$status]++; } else { $counts[$status] = 1; } } } } $str = 'var groupStatusPieData = ['; $i = 1; foreach ($counts as $k => $v) { $str .= '{ "x": "' . $i . '", "y": "' . $v . '", "text": "' . $k . '"},'; $i++; } $str .= ']; '; // load user prefs for chart theme $user = new userEntry(); $user->db = $this->db; $user->getByName($panoptes_current_user); $userPrefs = new userPrefs($this->db); $userPrefs->db = $this->db; $theme = $userPrefs->getPref($user->id, 'general', 'general_prefs_chart_theme'); if (is_null($theme)) { require_once dirname(realpath(__FILE__)) . '/../panoptes.php'; $panoptes = new panoptes(); $theme = $panoptes->config()->getConfigValue('web.default_chart_theme'); } $rtn['value'] .= $str; $rtn['value'] .= "var dv = document.createElement('div'); dv.id = '" . $prms['group_id'] . "' + '_gs_div'; dv.style.height = '200px'; dv.style.width = '200px'; node.appendChild(dv); var GS_pieChart = new dojox.charting.Chart2D('" . $prms['group_id'] . "' + '_gs_div', { title: '" . $grp->name . " summary', titleFont: 'normal normal bold 12pt Helvetica', titleGap: 5 }); GS_pieChart.setTheme(dojox.charting.themes." . $theme . "); GS_pieChart.addPlot('default', { type: 'Pie', labels: true, labelOffset: -30, radius: 50, fontColor: 'black'}); GS_pieChart.addSeries('" . $grp->name . "' + ' Summary', groupStatusPieData); new dojox.charting.action2d.MoveSlice(GS_pieChart, 'default'); GS_pieChart.render()"; } catch (PDOException $e) { throw $e; } return $rtn; }
/** * add group member * * add member id to group, creating group if it doesn't already exist * * @param args json params converted into an array * id device id to add to group * name name of group to add * @throws none * @return array containing result and possible error messages */ public function ajax_addGroupMember($args) { $data = array(); try { $grp = $this->getDeviceGroup(null, $args['name']); if (is_null($grp)) { // add new group entry $grp = new deviceGroup(); $grp->db($this->db); $grp->id = 0; $grp->name = $args['name']; $grp->commit(); $data['id'] = $grp->id; $data['name'] = $grp->name; } // add member to group $grp->addMember($args['id']); } catch (Exception $e) { return array('result' => 'failure', 'error' => $e->getMessage()); } return array('result' => 'success', 'data' => $data); }