Skip to content
Permalink
Browse files

Show Plugin if Installed and Enabled

Function getPluginByName added to class.plugin.php. This function has 2 variables that can be passed in: $name and $active (bool default false). It will return the name of a plugin if it is found in the database. If $active is true, it will also check to see if the plugin is active before returning the name of the plugin.

Using this function, we can be sure that the plugin is invisible and no extra code is run to try to log an audit if the plugin is disabled or not installed at all.
  • Loading branch information...
aydreeihn committed Jun 10, 2019
1 parent 69da645 commit 349c9823fff389360e778ddf02ce647b486bbf64
@@ -121,9 +121,11 @@ function update($key, $value) {
$before = $item->value;
$item->value = $value;
if ($before != $item->value) {
$type = array('type' => 'edited', 'data' => array('person' => $thisstaff->getName()->name, 'key' => $item->ht['key']));
Signal::send('object.edited', $item, $type);
if (PluginManager::getPluginByName('View auditing for tickets', true)) {
if ($before != $item->value) {
$type = array('type' => 'edited', 'data' => array('person' => $thisstaff->getName()->name, 'key' => $item->ht['key']));
Signal::send('object.edited', $item, $type);
}
}
return $item->save();
@@ -813,15 +813,17 @@ function update($vars, &$errors) {
if ($errors)
return false;
foreach ($vars as $key => $value) {
if ($key == 'status' && $this->getStatus() && strtolower($this->getStatus()) != $value) {
$loggedUpdate = true;
$type = array('type' => 'edited', 'data' => array('name' => $this->getName(), 'person' => $thisstaff->getName()->name, 'type' => ucfirst($value)));
Signal::send('object.edited', $this, $type);
} elseif (isset($this->$key) && ($this->$key != $value)) {
$loggedUpdate = true;
$type = array('type' => 'edited', 'data' => array('name' => $this->getName(), 'person' => $thisstaff->getName()->name, 'key' => $key));
Signal::send('object.edited', $this, $type);
if (PluginManager::getPluginByName('View auditing for tickets', true)) {
foreach ($vars as $key => $value) {
if ($key == 'status' && $this->getStatus() && strtolower($this->getStatus()) != $value) {
$loggedUpdate = true;
$type = array('type' => 'edited', 'data' => array('name' => $this->getName(), 'person' => $thisstaff->getName()->name, 'type' => ucfirst($value)));
Signal::send('object.edited', $this, $type);
} elseif (isset($this->$key) && ($this->$key != $value) && $key != 'members') {
$loggedUpdate = true;
$type = array('type' => 'edited', 'data' => array('name' => $this->getName(), 'person' => $thisstaff->getName()->name, 'key' => $key));
Signal::send('object.edited', $this, $type);
}
}
}
@@ -909,6 +911,8 @@ function update($vars, &$errors) {
}
function updateAccess($access, &$errors) {
global $thisstaff;
reset($access);
$dropped = array();
foreach ($this->extended as $DA)
@@ -935,6 +939,10 @@ function updateAccess($access, &$errors) {
'staff_id' => $staff_id, 'role_id' => $role_id
));
$this->extended->add($da);
if (PluginManager::getPluginByName('View auditing for tickets', true)) {
$type = array('type' => 'edited', 'data' => array('name' => $this->getName(), 'person' => $thisstaff->getName()->name, 'key' => 'Staff Added'));
Signal::send('object.edited', $this, $type);
}
}
else {
$da->role_id = $role_id;
@@ -947,6 +955,10 @@ function updateAccess($access, &$errors) {
return false;
if ($dropped) {
if (PluginManager::getPluginByName('View auditing for tickets', true)) {
$type = array('type' => 'edited', 'data' => array('name' => $this->getName(), 'person' => $thisstaff->getName()->name, 'key' => 'Staff Removed'));
Signal::send('object.edited', $this, $type);
}
$this->extended->saveAll();
$this->extended
->filter(array('staff_id__in' => array_keys($dropped)))
@@ -386,10 +386,12 @@ function update($vars, &$errors=false) {
if($errors) return false;
foreach ($vars as $key => $value) {
if (isset($this->$key) && ($this->$key != $value)) {
$type = array('type' => 'edited', 'data' => array('name' => $this->getName(), 'person' => $thisstaff->getName()->name, 'key' => $key));
Signal::send('object.edited', $this, $type);
if (PluginManager::getPluginByName('View auditing for tickets', true)) {
foreach ($vars as $key => $value) {
if (isset($this->$key) && ($this->$key != $value)) {
$type = array('type' => 'edited', 'data' => array('name' => $this->getName(), 'person' => $thisstaff->getName()->name, 'key' => $key));
Signal::send('object.edited', $this, $type);
}
}
}
@@ -362,10 +362,12 @@ function update($vars,&$errors) {
$vars['target'] = 'Email';
}
foreach ($vars as $key => $value) {
if (isset($this->$key) && ($this->$key != $value) && $key != 'rules' && $key != 'actions') {
$type = array('type' => 'edited', 'data' => array('name' => $this->getName(), 'person' => $thisstaff->getName()->name, 'key' => $key));
Signal::send('object.edited', $this, $type);
if (PluginManager::getPluginByName('View auditing for tickets', true)) {
foreach ($vars as $key => $value) {
if (isset($this->$key) && ($this->$key != $value) && $key != 'rules' && $key != 'actions') {
$type = array('type' => 'edited', 'data' => array('name' => $this->getName(), 'person' => $thisstaff->getName()->name, 'key' => $key));
Signal::send('object.edited', $this, $type);
}
}
}
@@ -409,8 +409,10 @@ function update($vars, &$errors) {
$errors[$f] = sprintf(__('%s is required'), mb_convert_case($f, MB_CASE_TITLE));
elseif (isset($vars[$f])) {
if ($vars[$f] != $this->get($f)) {
$type = array('type' => 'edited', 'data' => array('name' => $this->getName(), 'person' => $thisstaff->getName()->name, 'key' => $f));
Signal::send('object.edited', $this, $type);
if (PluginManager::getPluginByName('View auditing for tickets', true)) {
$type = array('type' => 'edited', 'data' => array('name' => $this->getName(), 'person' => $thisstaff->getName()->name, 'key' => $f));
Signal::send('object.edited', $this, $type);
}
$this->set($f, $vars[$f]);
}
}
@@ -234,7 +234,8 @@ function getSubMenus(){
switch(strtolower($k)){
case 'dashboard':
$subnav[]=array('desc'=>__('System Logs'),'href'=>'logs.php','iconclass'=>'logs');
$subnav[]=array('desc'=>__('Audit Logs'),'href'=>'audits.php','iconclass'=>'open');
if (PluginManager::getPluginByName('View auditing for tickets', true))
$subnav[]=array('desc'=>__('Audit Logs'),'href'=>'audits.php','iconclass'=>'open');
$subnav[]=array('desc'=>__('Information'),'href'=>'system.php','iconclass'=>'preferences');
break;
case 'settings':
@@ -459,8 +459,10 @@ function update($vars, &$errors) {
));
}
$type = array('type' => 'edited', 'data' => array('name' => $this->getName(), 'person' => $thisstaff->getName()->name));
Signal::send('object.edited', $this, $type);
if (PluginManager::getPluginByName('View auditing for tickets', true)) {
$type = array('type' => 'edited', 'data' => array('name' => $this->getName(), 'person' => $thisstaff->getName()->name));
Signal::send('object.edited', $this, $type);
}
return $this->save();
}
@@ -541,8 +543,10 @@ static function fromVars($vars) {
}
Signal::send('organization.created', $org);
$type = array('type' => 'created', 'data' => array('name' => $org->getName(), 'person' => $thisstaff->getName()->name));
Signal::send('object.created', $org, $type);
if (PluginManager::getPluginByName('View auditing for tickets', true)) {
$type = array('type' => 'created', 'data' => array('name' => $org->getName(), 'person' => $thisstaff->getName()->name));
Signal::send('object.created', $org, $type);
}
return $org;
}
@@ -270,10 +270,12 @@ function update($vars, &$errors, $allowempty=false) {
if($errors) return false;
foreach ($vars as $key => $value) {
if (isset($this->$key) && ($this->$key != $value)) {
$type = array('type' => 'edited', 'data' => array('name' => $this->getName(), 'person' => $thisstaff->getName()->name, 'key' => $key));
Signal::send('object.edited', $this, $type);
if (PluginManager::getPluginByName('View auditing for tickets', true)) {
foreach ($vars as $key => $value) {
if (isset($this->$key) && ($this->$key != $value)) {
$type = array('type' => 'edited', 'data' => array('name' => $this->getName(), 'person' => $thisstaff->getName()->name, 'key' => $key));
Signal::send('object.edited', $this, $type);
}
}
}
@@ -211,6 +211,16 @@ static function allInstalled() {
return static::$plugin_list;
}
static function getPluginByName($name, $active=false) {
$sql = sprintf('SELECT * FROM %s WHERE name="%s"', PLUGIN_TABLE, $name);
if ($active)
$sql = sprintf('%s AND isactive = true', $sql);
if (!($res = db_query($sql)))
return false;
$ht = db_fetch_array($res);
return $ht['name'];
}
static function allActive() {
$plugins = array();
foreach (static::allInstalled() as $p)
@@ -138,18 +138,22 @@ private function updatePerms($vars, &$errors=array()) {
$config = array();
$permissions = $this->getPermission();
foreach ($vars as $k => $val) {
if (!array_key_exists($val, $permissions->perms)) {
$type = array('type' => 'edited', 'data' => array('name' => $this->getName(), 'person' => $thisstaff->getName()->name, 'key' => $val));
Signal::send('object.edited', $this, $type);
if (PluginManager::getPluginByName('View auditing for tickets', true)) {
foreach ($vars as $k => $val) {
if (!array_key_exists($val, $permissions->perms)) {
$type = array('type' => 'edited', 'data' => array('name' => $this->getName(), 'person' => $thisstaff->getName()->name, 'key' => $val));
Signal::send('object.edited', $this, $type);
}
}
}
foreach (RolePermission::allPermissions() as $g => $perms) {
foreach($perms as $k => $v) {
if (!in_array($k, $vars) && array_key_exists($k, $permissions->perms)) {
$type = array('type' => 'edited', 'data' => array('name' => $this->getName(), 'person' => $thisstaff->getName()->name, 'key' => $k));
Signal::send('object.edited', $this, $type);
if (PluginManager::getPluginByName('View auditing for tickets', true)) {
if (!in_array($k, $vars) && array_key_exists($k, $permissions->perms)) {
$type = array('type' => 'edited', 'data' => array('name' => $this->getName(), 'person' => $thisstaff->getName()->name, 'key' => $k));
Signal::send('object.edited', $this, $type);
}
}
$permissions->set($k, in_array($k, $vars) ? 1 : 0);
}
@@ -158,11 +158,13 @@ function update($vars, &$errors) {
if ($errors)
return false;
foreach ($vars as $key => $value) {
if (isset($this->$key) && ($this->$key != $value)) {
$loggedUpdate = true;
$type = array('type' => 'edited', 'data' => array('name' => $this->getName(), 'person' => $thisstaff->getName()->name, 'key' => $key));
Signal::send('object.edited', $this, $type);
if (PluginManager::getPluginByName('View auditing for tickets', true)) {
foreach ($vars as $key => $value) {
if (isset($this->$key) && ($this->$key != $value)) {
$loggedUpdate = true;
$type = array('type' => 'edited', 'data' => array('name' => $this->getName(), 'person' => $thisstaff->getName()->name, 'key' => $key));
Signal::send('object.edited', $this, $type);
}
}
}
@@ -177,7 +179,7 @@ function update($vars, &$errors) {
| (isset($vars['transient']) ? self::FLAG_TRANSIENT : 0);
if ($this->save()) {
if (!$loggedUpdate) {
if (!$loggedUpdate && PluginManager::getPluginByName('View auditing for tickets', true)) {
$type = array('type' => 'edited', 'data' => array('name' => $this->getName(), 'person' => $thisstaff->getName()->name));
Signal::send('object.edited', $this, $type);
}
@@ -741,11 +741,12 @@ function updateProfile($vars, &$errors) {
}
}
foreach ($vars as $key => $value) {
if (isset($this->$key) && ($this->$key != $value)) {
$loggedUpdate = true;
$type = array('type' => 'edited', 'data' => array('name' => $this->getName()->name, 'person' => $thisstaff->getName()->name, 'key' => $key));
Signal::send('object.edited', $this, $type);
if (PluginManager::getPluginByName('View auditing for tickets', true)) {
foreach ($vars as $key => $value) {
if (isset($this->$key) && ($this->$key != $value)) {
$type = array('type' => 'edited', 'data' => array('name' => $this->getName()->name, 'person' => $thisstaff->getName()->name, 'key' => $key));
Signal::send('object.edited', $this, $type);
}
}
}
@@ -1151,11 +1152,13 @@ function update($vars, &$errors) {
// Update the local permissions
$this->updatePerms($vars['perms'], $errors);
foreach ($vars as $key => $value) {
if ($key == 'islocked') $key = 'isactive';
if (isset($this->$key) && ($this->$key != $value) && ($key != 'perms') && ($key != 'teams')) {
$type = array('type' => 'edited', 'data' => array('name' => $this->getName()->name, 'person' => $thisstaff->getName()->name, 'key' => $key));
Signal::send('object.edited', $this, $type);
if (PluginManager::getPluginByName('View auditing for tickets', true)) {
foreach ($vars as $key => $value) {
if ($key == 'islocked') $key = 'isactive';
if (isset($this->$key) && ($this->$key != $value) && ($key != 'perms') && ($key != 'teams')) {
$type = array('type' => 'edited', 'data' => array('name' => $this->getName()->name, 'person' => $thisstaff->getName()->name, 'key' => $key));
Signal::send('object.edited', $this, $type);
}
}
}
@@ -1253,15 +1256,15 @@ function updatePerms($vars, &$errors=array()) {
}
$permissions = $this->getPermission();
foreach ($vars as $k => $val) {
if (!array_key_exists($val, $permissions->perms)) {
if (!array_key_exists($val, $permissions->perms) && PluginManager::getPluginByName('View auditing for tickets', true)) {
$type = array('type' => 'edited', 'data' => array('name' => $this->getName()->name, 'person' => $thisstaff->getName()->name, 'key' => $val));
Signal::send('object.edited', $this, $type);
}
}
foreach (RolePermission::allPermissions() as $g => $perms) {
foreach ($perms as $k => $v) {
if (!in_array($k, $vars) && array_key_exists($k, $permissions->perms)) {
if (!in_array($k, $vars) && array_key_exists($k, $permissions->perms) && PluginManager::getPluginByName('View auditing for tickets', true)) {
$type = array('type' => 'edited', 'data' => array('name' => $this->getName()->name, 'person' => $thisstaff->getName()->name, 'key' => $k));
Signal::send('object.edited', $this, $type);
}

0 comments on commit 349c982

Please sign in to comment.
You can’t perform that action at this time.