From c06dba17dff5ec547f55d68b692f390ae40c517d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come@opensides.be> Date: Tue, 23 Aug 2016 15:46:59 +0200 Subject: [PATCH] Fixes #946 Cleanup of plugin/simplePlugin, remove of some deprecated code --- include/class_CopyPasteHandler.inc | 60 +-- include/class_plugin.inc | 268 +----------- include/simpleplugin/class_simplePlugin.inc | 446 +++++++++++++++----- include/simpleplugin/class_simpleTabs.inc | 54 +-- 4 files changed, 366 insertions(+), 462 deletions(-) diff --git a/include/class_CopyPasteHandler.inc b/include/class_CopyPasteHandler.inc index 51be87f49..737f05387 100644 --- a/include/class_CopyPasteHandler.inc +++ b/include/class_CopyPasteHandler.inc @@ -66,33 +66,23 @@ class CopyPasteHandler /*! * \brief Entry entry to Copy & Paste queue. * A Queue entry is represented as follows. - * array['file_name'] - Position on hdd * array['method'] - 'copy' or 'cut' * array['dn'] - the dn of the object added to the queue - * array['tab_class'] - Tab object that should be used to initialize the new object - * array['tab_object'] - Tab object name used to initialize correct object Type like USERTABS + * array['type'] - Object type * * \param String $dn The dn of the object added to the queue * * \param String $action Copy or Cut * - * \param String $tab_class Tab object that should be used to initialize the new object - * - * \param String $tab_object Tab object name used to initialize correct object Type like USERTABS - * - * \param String $tab_acl_category Tab with acl category - * - * \param Object $parent the parent to set to the tab object + * \param String $type the type of the object */ - function add_to_queue() + function add_to_queue($dn, $action, $type) { global $config; - $dn = func_get_arg(0); - @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $dn, "add_to_queue"); - $action = func_get_arg(1); + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $dn, 'add_to_queue'); - if (!in_array($action, array("cut","copy"))) { - trigger_error(sprintf("Specified action '%s' does not exists for copy & paste.", $action)); + if (!in_array($action, array('cut','copy'))) { + trigger_error(sprintf('Specified action "%s" does not exists for copy & paste.', $action)); return FALSE; } @@ -100,41 +90,15 @@ class CopyPasteHandler $tmp['method'] = $action; $tmp['dn'] = $dn; + $tmp['type'] = $type; - if (func_num_args() == 3) { - $type = func_get_arg(2); - $tmp['type'] = $type; - $infos = objects::infos($type); - $tmp['tab_acl_category'] = $infos['aclCategory']; - $tmp['parent'] = NULL; - } else { - // Deprecated - $tab_class = func_get_arg(2); - $tab_object = func_get_arg(3); - $tab_acl_category = func_get_arg(4); - $parent = NULL; - if (func_num_args() > 5) { - $parent = func_get_arg(5); - } - - if (!class_available($tab_class)) { - trigger_error(sprintf("Specified class object '%s' does not exists.", $tab_class)); - return FALSE; - } - - if (!isset($config->data['TABS'][$tab_object])) { - trigger_error(sprintf("Specified tab object '%s' does not exists.", $tab_object)); - return FALSE; - } - $tmp['tab_class'] = $tab_class; - $tmp['tab_object'] = $tab_object; - $tmp['tab_acl_category'] = $tab_acl_category; - $tmp['parent'] = $parent; - } + $infos = objects::infos($type); + $tmp['tab_acl_category'] = $infos['aclCategory']; + $tmp['parent'] = NULL; - $this->queue[] = $tmp; + $this->queue[] = $tmp; if ($action == 'copy') { - $this->objectList[] = $tmp; + $this->objectList[] = $tmp; } $this->require_update = TRUE; diff --git a/include/class_plugin.inc b/include/class_plugin.inc index 74d33801a..dba44faf0 100644 --- a/include/class_plugin.inc +++ b/include/class_plugin.inc @@ -189,21 +189,6 @@ class plugin $this->initially_was_account = $this->is_account; } - function is_this_account($attrs) - { - $found = TRUE; - foreach ($this->objectclasses as $obj) { - if (preg_match('/top/i', $obj)) { - continue; - } - if (!isset($attrs['objectClass']) || !in_array_ics ($obj, $attrs['objectClass'])) { - $found = FALSE; - break; - } - } - return $found; - } - function prepareSavedAttributes() { /* Prepare saved attributes */ @@ -365,11 +350,6 @@ class plugin } } - function setTemplate ($bool) - { - $this->is_template = $bool; - } - static function tpl_fetch_template($dn) { global $config; @@ -734,34 +714,6 @@ class plugin return $fields; } - /*! - * \brief Show header message for tab dialogs - * - * \param string $button_text The button text - * - * \param string $text The text - * - * \param boolean $disabled FALSE - */ - function show_enable_header($button_text, $text, $disabled = FALSE, $name = 'modify_state') - { - return $this->show_header($button_text, $text, FALSE, $disabled, $name); - } - - /*! - * \brief Show header message for tab dialogs - * - * \param string $button_text The button text - * - * \param string $text The text - * - * \param boolean $disabled FALSE - */ - function show_disable_header($button_text, $text, $disabled = FALSE, $name = 'modify_state') - { - return $this->show_header($button_text, $text, TRUE, $disabled, $name); - } - /*! * \brief Show header message for tab dialogs * @@ -917,214 +869,6 @@ class plugin return TRUE; } - /*! \brief This function returns an LDAP filter for this plugin object classes - */ - function getObjectClassFilter () - { - if (!empty($this->objectclasses)) { - return '(&(objectClass='.implode(')(objectClass=', $this->objectclasses).'))'; - } else { - return ''; - } - } - - function handleForeignKeys ($olddn = NULL, $newdn = NULL, $mode = 'move') - { - if (($olddn !== NULL) && ($olddn == $newdn)) { - return; - } - if ($this->is_template) { - return; - } - $this->browseForeignKeys( - 'handle_'.$mode, - $olddn, - $newdn - ); - } - - function browseForeignKeys($mode, $param1 = NULL, $param2 = NULL) - { - if (preg_match('/^handle_/', $mode)) { - $olddn = $param1; - $newdn = $param2; - $classes = array(get_class($this)); - } elseif ($mode == 'references') { - $classes = array_keys($this->parent->by_object); - } - // We group by objetType concerned - $foreignRefs = array(); - foreach ($classes as $tabclass) { - $infos = pluglist::pluginInfos($tabclass); - foreach ($infos['plForeignRefs'] as $field => $refs) { - if (preg_match('/^handle_/', $mode)) { - if ($newdn !== NULL) { - // Move action - if (($field != 'dn') && ($mode == 'handle_move')) { - // We only change dn - continue; - } - } elseif ($olddn === NULL) { - // Edit action - if ($field == 'dn') { - // dn did not change - continue; - } elseif (!$this->attributeHaveChanged($field)) { - // only look at changed attributes - continue; - } - } - // else = delete action, all fields are concerned, nothing to do here - } - foreach ($refs as $ref) { - $class = $ref[0]; - $ofield = $ref[1]; - $filter = $ref[2]; - $cinfos = pluglist::pluginInfos($class); - foreach ($cinfos['plObjectType'] as $key => $objectType) { - if (!is_numeric($key)) { - $objectType = $key; - } - if (preg_match('/^handle_/', $mode)) { - if ($field == 'dn') { - $oldvalue = $olddn; - $newvalue = $newdn; - } elseif (($olddn !== NULL) && ($newdn === NULL)) { - $oldvalue = $this->attributeInitialValue($field); - $newvalue = NULL; - } else { - $oldvalue = $this->attributeInitialValue($field); - $newvalue = $this->attributeValue($field); - } - $foreignRefs[$objectType]['refs'][$class][$ofield] = - array( - 'field' => $field, - 'oldvalue' => $oldvalue, - 'newvalue' => $newvalue, - 'tab' => $tabclass, - ); - $filter = plugin::tpl_parse_string($filter, array('oldvalue' => $oldvalue, 'newvalue' => $newvalue), 'ldap_escape_f'); - } elseif ($mode == 'references') { - $foreignRefs[$objectType]['refs'][$class]['name'] = $cinfos['plShortName']; - $foreignRefs[$objectType]['refs'][$class]['fields'][$ofield] = - array( - 'tab' => $tabclass, - 'tabname' => $this->parent->by_name[$tabclass], - 'field' => $field, - 'value' => $this->parent->by_object[$tabclass]->$field, - ); - $filter = plugin::tpl_parse_string($filter, array('oldvalue' => $this->parent->by_object[$tabclass]->$field), 'ldap_escape_f'); - } - if (!preg_match('/^\(.*\)$/', $filter)) { - $filter = '('.$filter.')'; - } - $foreignRefs[$objectType]['filters'][$filter] = $filter; - } - } - } - } - - /* Back up POSTÂ content */ - $SAVED_POST = $_POST; - $refs = array(); - // For each concerned objectType - foreach ($foreignRefs as $objectType => $tabRefs) { - // Compute filter - $filters = array_values($tabRefs['filters']); - $filter = '(|'.join($filters).')'; - // Search objects - try { - $objects = objects::ls($objectType, array('dn' => 'raw'), NULL, $filter); - } catch (NonExistingObjectTypeException $e) { - continue; - } catch (EmptyFilterException $e) { - continue; - } - // For each object of this type - foreach (array_keys($objects) as $dn) { - /* Avoid sending POSTÂ to opened objects */ - $_POST = array(); - // Build the object - $tabobject = objects::open($dn, $objectType); - if (preg_match('/^handle_/', $mode)) { - // For each tab concerned - foreach ($tabRefs['refs'] as $tab => $fieldRefs) { - // If the tab is activated on this object - if (isset($tabobject->by_object[$tab])) { - // For each field - foreach ($fieldRefs as $ofield => $field) { - // call plugin::foreignKeyUpdate(ldapname, oldvalue, newvalue, source) on the object - $tabobject->by_object[$tab]->foreignKeyUpdate( - $ofield, - $field['oldvalue'], - $field['newvalue'], - array( - 'CLASS' => $field['tab'], - 'FIELD' => $field['field'], - 'MODE' => preg_replace('/^handle_/', '', $mode), - 'DN' => $this->dn, - ) - ); - } - $tabobject->by_object[$tab]->save_object(); - $tabobject->by_object[$tab]->save(); - } - } - } elseif ($mode == 'references') { - // For each tab concerned - foreach ($tabRefs['refs'] as $tab => $tab_infos) { - // If the tab is activated on this object - if (isset($tabobject->by_object[$tab])) { - // For each field - foreach ($tab_infos['fields'] as $ofield => $field) { - if ($tabobject->by_object[$tab]->foreignKeyCheck( - $ofield, - $field['value'], - array( - 'CLASS' => $field['tab'], - 'FIELD' => $field['field'], - 'DN' => $this->dn, - ) - )) { - if (!isset($refs[$dn])) { - $refs[$dn] = array( - 'link' => '', - 'tabs' => array(), - ); - try { - $refs[$dn]['link'] = objects::link($dn, $objectType); - } catch (Exception $e) { - trigger_error("Could not create link to $dn: ".$e->getMessage()); - $refs[$dn]['link'] = $dn; - } - } - if (!isset($refs[$dn]['tabs'][$tab])) { - $refs[$dn]['tabs'][$tab] = array( - 'link' => '', - 'fields' => array(), - ); - try { - $refs[$dn]['tabs'][$tab]['link'] = objects::link($dn, $objectType, "tab_$tab", sprintf(_('Tab "%s"'), $tab_infos['name'])); - } catch (Exception $e) { - trigger_error("Could not create link to $dn $tab: ".$e->getMessage()); - $refs[$dn]['tabs'][$tab]['link'] = $tab; - } - } - $refs[$dn]['tabs'][$tab]['fields'][$ofield] = $field; - } - } - } - } - } - } - } - /* Restore POST */ - $_POST = $SAVED_POST; - if ($mode == 'references') { - return $refs; - } - } - /*! \brief Forward command execution requests * to the pre/post hook execution method. * @@ -1150,7 +894,7 @@ class plugin break; default: - trigger_error(sprintf('Invalid %s event type given %s! Valid types are [add,modify,remove].', strtolower($when), $mode)); + trigger_error(sprintf('Invalid %s event type given: "%s"! Valid types are: add, modify, remove.', strtolower($when), $mode)); break; } } @@ -1260,16 +1004,6 @@ class plugin return $reason; } - /*! - * \brief Return plugin informations for acl handling - * - * \return an array - */ - static function plInfo() - { - return array(); - } - /*! * \brief Set acl base * diff --git a/include/simpleplugin/class_simplePlugin.inc b/include/simpleplugin/class_simplePlugin.inc index 9138703e6..11bcc5021 100644 --- a/include/simpleplugin/class_simplePlugin.inc +++ b/include/simpleplugin/class_simplePlugin.inc @@ -156,9 +156,24 @@ class simplePlugin extends plugin } } + function is_this_account($attrs) + { + $found = TRUE; + foreach ($this->objectclasses as $obj) { + if (preg_match('/top/i', $obj)) { + continue; + } + if (!isset($attrs['objectClass']) || !in_array_ics ($obj, $attrs['objectClass'])) { + $found = FALSE; + break; + } + } + return $found; + } + function setTemplate ($bool) { - parent::setTemplate($bool); + $this->is_template = $bool; if ($this->is_template && $this->mainTab) { /* Unshift special section for template infos */ $this->attributesInfo = array_merge( @@ -190,6 +205,17 @@ class simplePlugin extends plugin } } + /*! \brief This function returns an LDAP filter for this plugin object classes + */ + function getObjectClassFilter () + { + if (!empty($this->objectclasses)) { + return '(&(objectClass='.implode(')(objectClass=', $this->objectclasses).'))'; + } else { + return ''; + } + } + protected function loadAttributes() { // We load attributes values @@ -361,9 +387,9 @@ class simplePlugin extends plugin /* Show tab dialog headers */ $plInfo = pluglist::pluginInfos(get_class($this)); if ($this->parent !== NULL) { + $disabled = $this->acl_skip_write(); + $depends = array(); if ($this->is_account) { - $disabled = $this->acl_skip_write(); - $depends = array(); if (isset($plInfo['plDepending'])) { foreach ($plInfo['plDepending'] as $plugin) { if (isset($this->parent->by_object[$plugin]) && @@ -374,15 +400,14 @@ class simplePlugin extends plugin } } } - $this->header = $this->show_disable_header( + $this->header = $this->show_header( msgPool::removeFeaturesButton($plInfo['plShortName']), msgPool::featuresEnabled($plInfo['plShortName'], $depends), + $this->is_account, $disabled, get_class($this).'_modify_state' ); } else { - $disabled = $this->acl_skip_write(); - $depends = array(); if (isset($plInfo['plDepends'])) { foreach ($plInfo['plDepends'] as $plugin) { if (!isset($this->parent->by_object[$plugin]) || @@ -393,9 +418,10 @@ class simplePlugin extends plugin } } } - $this->header = $this->show_enable_header( + $this->header = $this->show_header( msgPool::addFeaturesButton($plInfo['plShortName']), msgPool::featuresDisabled($plInfo['plShortName'], $depends), + $this->is_account, $disabled, get_class($this).'_modify_state' ); @@ -599,7 +625,8 @@ class simplePlugin extends plugin } } - protected function pre_remove () { + protected function pre_remove () + { if ($this->initially_was_account) { return $this->handle_pre_events('remove'); } @@ -762,7 +789,8 @@ class simplePlugin extends plugin } } - protected function pre_save () { + protected function pre_save () + { if ($this->initially_was_account) { return $this->handle_pre_events('modify'); } else { @@ -862,6 +890,302 @@ class simplePlugin extends plugin return $messages; } + function handleForeignKeys ($olddn = NULL, $newdn = NULL, $mode = 'move') + { + if (($olddn !== NULL) && ($olddn == $newdn)) { + return; + } + if ($this->is_template) { + return; + } + $this->browseForeignKeys( + 'handle_'.$mode, + $olddn, + $newdn + ); + } + + function browseForeignKeys($mode, $param1 = NULL, $param2 = NULL) + { + if (preg_match('/^handle_/', $mode)) { + $olddn = $param1; + $newdn = $param2; + $classes = array(get_class($this)); + } elseif ($mode == 'references') { + $classes = array_keys($this->parent->by_object); + } + // We group by objetType concerned + $foreignRefs = array(); + foreach ($classes as $tabclass) { + $infos = pluglist::pluginInfos($tabclass); + foreach ($infos['plForeignRefs'] as $field => $refs) { + if (preg_match('/^handle_/', $mode)) { + if ($newdn !== NULL) { + // Move action + if (($field != 'dn') && ($mode == 'handle_move')) { + // We only change dn + continue; + } + } elseif ($olddn === NULL) { + // Edit action + if ($field == 'dn') { + // dn did not change + continue; + } elseif (!$this->attributeHaveChanged($field)) { + // only look at changed attributes + continue; + } + } + // else = delete action, all fields are concerned, nothing to do here + } + foreach ($refs as $ref) { + $class = $ref[0]; + $ofield = $ref[1]; + $filter = $ref[2]; + $cinfos = pluglist::pluginInfos($class); + foreach ($cinfos['plObjectType'] as $key => $objectType) { + if (!is_numeric($key)) { + $objectType = $key; + } + if (preg_match('/^handle_/', $mode)) { + if ($field == 'dn') { + $oldvalue = $olddn; + $newvalue = $newdn; + } elseif (($olddn !== NULL) && ($newdn === NULL)) { + $oldvalue = $this->attributeInitialValue($field); + $newvalue = NULL; + } else { + $oldvalue = $this->attributeInitialValue($field); + $newvalue = $this->attributeValue($field); + } + $foreignRefs[$objectType]['refs'][$class][$ofield] = + array( + 'field' => $field, + 'oldvalue' => $oldvalue, + 'newvalue' => $newvalue, + 'tab' => $tabclass, + ); + $filter = plugin::tpl_parse_string($filter, array('oldvalue' => $oldvalue, 'newvalue' => $newvalue), 'ldap_escape_f'); + } elseif ($mode == 'references') { + $foreignRefs[$objectType]['refs'][$class]['name'] = $cinfos['plShortName']; + $foreignRefs[$objectType]['refs'][$class]['fields'][$ofield] = + array( + 'tab' => $tabclass, + 'tabname' => $this->parent->by_name[$tabclass], + 'field' => $field, + 'value' => $this->parent->by_object[$tabclass]->$field, + ); + $filter = plugin::tpl_parse_string($filter, array('oldvalue' => $this->parent->by_object[$tabclass]->$field), 'ldap_escape_f'); + } + if (!preg_match('/^\(.*\)$/', $filter)) { + $filter = '('.$filter.')'; + } + $foreignRefs[$objectType]['filters'][$filter] = $filter; + } + } + } + } + + /* Back up POSTÂ content */ + $SAVED_POST = $_POST; + $refs = array(); + // For each concerned objectType + foreach ($foreignRefs as $objectType => $tabRefs) { + // Compute filter + $filters = array_values($tabRefs['filters']); + $filter = '(|'.join($filters).')'; + // Search objects + try { + $objects = objects::ls($objectType, array('dn' => 'raw'), NULL, $filter); + } catch (NonExistingObjectTypeException $e) { + continue; + } catch (EmptyFilterException $e) { + continue; + } + // For each object of this type + foreach (array_keys($objects) as $dn) { + /* Avoid sending POSTÂ to opened objects */ + $_POST = array(); + // Build the object + $tabobject = objects::open($dn, $objectType); + if (preg_match('/^handle_/', $mode)) { + // For each tab concerned + foreach ($tabRefs['refs'] as $tab => $fieldRefs) { + // If the tab is activated on this object + if (isset($tabobject->by_object[$tab])) { + // For each field + foreach ($fieldRefs as $ofield => $field) { + // call plugin::foreignKeyUpdate(ldapname, oldvalue, newvalue, source) on the object + $tabobject->by_object[$tab]->foreignKeyUpdate( + $ofield, + $field['oldvalue'], + $field['newvalue'], + array( + 'CLASS' => $field['tab'], + 'FIELD' => $field['field'], + 'MODE' => preg_replace('/^handle_/', '', $mode), + 'DN' => $this->dn, + ) + ); + } + $tabobject->by_object[$tab]->save_object(); + $tabobject->by_object[$tab]->save(); + } + } + } elseif ($mode == 'references') { + // For each tab concerned + foreach ($tabRefs['refs'] as $tab => $tab_infos) { + // If the tab is activated on this object + if (isset($tabobject->by_object[$tab])) { + // For each field + foreach ($tab_infos['fields'] as $ofield => $field) { + if ($tabobject->by_object[$tab]->foreignKeyCheck( + $ofield, + $field['value'], + array( + 'CLASS' => $field['tab'], + 'FIELD' => $field['field'], + 'DN' => $this->dn, + ) + )) { + if (!isset($refs[$dn])) { + $refs[$dn] = array( + 'link' => '', + 'tabs' => array(), + ); + try { + $refs[$dn]['link'] = objects::link($dn, $objectType); + } catch (Exception $e) { + trigger_error("Could not create link to $dn: ".$e->getMessage()); + $refs[$dn]['link'] = $dn; + } + } + if (!isset($refs[$dn]['tabs'][$tab])) { + $refs[$dn]['tabs'][$tab] = array( + 'link' => '', + 'fields' => array(), + ); + try { + $refs[$dn]['tabs'][$tab]['link'] = objects::link($dn, $objectType, "tab_$tab", sprintf(_('Tab "%s"'), $tab_infos['name'])); + } catch (Exception $e) { + trigger_error("Could not create link to $dn $tab: ".$e->getMessage()); + $refs[$dn]['tabs'][$tab]['link'] = $tab; + } + } + $refs[$dn]['tabs'][$tab]['fields'][$ofield] = $field; + } + } + } + } + } + } + } + /* Restore POST */ + $_POST = $SAVED_POST; + if ($mode == 'references') { + return $refs; + } + } + + /* + * \brief Adapt from template, using 'dn' + * + * \param string $dn The DN + * + * \param array $skip A new array + */ + function adapt_from_template($attrs, $skip = array()) + { + $this->attrs = $attrs; + + /* Walk through attributes */ + foreach ($this->attributesAccess as $ldapName => &$attr) { + /* Skip the ones in skip list */ + if (in_array($ldapName, $skip)) { + continue; + } + /* Load values */ + $attr->loadValue($this->attrs); + } + unset($attr); + + /* Is Account? */ + $this->is_account = $this->is_this_account($this->attrs); + } + + protected function attributeHaveChanged($field) + { + return $this->attributesAccess[$field]->hasChanged(); + } + + protected function attributeValue($field) + { + return $this->attributesAccess[$field]->getValue(); + } + + protected function attributeInitialValue($field) + { + return $this->attributesAccess[$field]->getInitialValue(); + } + + function foreignKeyUpdate ($field, $oldvalue, $newvalue, $source) + { + if (!isset($source['MODE'])) { + $source['MODE'] = 'move'; + } + $this->attributesAccess[$field]->foreignKeyUpdate($oldvalue, $newvalue, $source); + } + + /* + * Source is an array like this: + * array( + * 'CLASS' => class, + * 'FIELD' => field, + * 'DN' => dn, + * 'MODE' => mode + * ) + * mode being either 'copy' or 'move', defaults to 'move' + */ + function foreignKeyCheck ($field, $value, $source) + { + return $this->attributesAccess[$field]->foreignKeyCheck($value, $source); + } + + function deserializeValues($values, $checkAcl = TRUE) + { + foreach ($values as $name => $value) { + if (isset($this->attributesAccess[$name])) { + if (!$checkAcl || $this->acl_is_writeable($this->attributesAccess[$name]->getAcl())) { + $this->attributesAccess[$name]->setValue($value); + } else { + return sprintf(_('You don\'t have sufficient rights to edit field "%s"'), $name); + } + } else { + return sprintf(_('Unknown field "%s"'), $name); + } + } + return TRUE; + } + + /* Returns TRUE if this attribute should be asked in the creation by template dialog */ + function showInTemplate($attr, $templateAttrs) + { + if (isset($templateAttrs[$attr])) { + return FALSE; + } + return TRUE; + } + + /*! + * \brief Return plugin informations for acl handling + * + * \return an array + */ + static function plInfo() + { + return array(); + } + /*! \brief This function generate the needed ACLs for a given attribtues array * * \param array $attributesInfo the attribute array @@ -881,17 +1205,6 @@ class simplePlugin extends plugin return $plProvidedAcls; } - /*! \brief This function is the needed main.inc for users tab - * - * \param array $classname the plugin class name - */ - static function userMainInc ($classname) - { - global $ui; - trigger_error("userMainInc is deprecated"); - return self::mainInc($classname, $ui->dn); - } - /*! \brief This function is the needed main.inc for plugins that are not used inside a management class * * \param array $classname the class name to read plInfo from. (plIcon, plShortname and plCategory are gonna be used) @@ -910,7 +1223,7 @@ class simplePlugin extends plugin global $remove_lock, $cleanup, $display, $config, $plug, $ui; $plInfo = pluglist::pluginInfos($classname); - $plIcon = (isset($plInfo['plIcon'])?$plInfo['plIcon']:'plugin.png'); + $plIcon = (isset($plInfo['plIcon']) ? $plInfo['plIcon'] : 'plugin.png'); $plHeadline = $plInfo['plTitle']; if ($objectType === FALSE) { $key = key($plInfo['plObjectType']); @@ -919,7 +1232,7 @@ class simplePlugin extends plugin } $objectType = $key; } - $plCategory = (isset($plInfo['plCategory'])?$plInfo['plCategory']:array('user')); + $plCategory = (isset($plInfo['plCategory']) ? $plInfo['plCategory'] : array('user')); $key = key($plCategory); if (is_numeric($key)) { $plCategory = $plCategory[$key]; @@ -1059,94 +1372,5 @@ class simplePlugin extends plugin $display = print_header($plIcon, $plHeadline, $info).$display; } } - - /* - * \brief Adapt from template, using 'dn' - * - * \param string $dn The DN - * - * \param array $skip A new array - */ - function adapt_from_template($attrs, $skip = array()) - { - $this->attrs = $attrs; - - /* Walk through attributes */ - foreach ($this->attributesAccess as $ldapName => &$attr) { - /* Skip the ones in skip list */ - if (in_array($ldapName, $skip)) { - continue; - } - /* Load values */ - $attr->loadValue($this->attrs); - } - unset($attr); - - /* Is Account? */ - $this->is_account = $this->is_this_account($this->attrs); - } - - protected function attributeHaveChanged($field) - { - return $this->attributesAccess[$field]->hasChanged(); - } - - protected function attributeValue($field) - { - return $this->attributesAccess[$field]->getValue(); - } - - protected function attributeInitialValue($field) - { - return $this->attributesAccess[$field]->getInitialValue(); - } - - function foreignKeyUpdate ($field, $oldvalue, $newvalue, $source) - { - if (!isset($source['MODE'])) { - $source['MODE'] = 'move'; - } - $this->attributesAccess[$field]->foreignKeyUpdate($oldvalue, $newvalue, $source); - } - - /* - * Source is an array like this: - * array( - * 'CLASS' => class, - * 'FIELD' => field, - * 'DN' => dn, - * 'MODE' => mode - * ) - * mode being either 'copy' or 'move', defaults to 'move' - */ - function foreignKeyCheck ($field, $value, $source) - { - return $this->attributesAccess[$field]->foreignKeyCheck($value, $source); - } - - function deserializeValues($values, $checkAcl = TRUE) { - foreach ($values as $name => $value) { - if (isset($this->attributesAccess[$name])) { - if (!$checkAcl || $this->acl_is_writeable($this->attributesAccess[$name]->getAcl())) { - $this->attributesAccess[$name]->setValue($value); - } else { - return sprintf(_('You don\'t have sufficient rights to edit field "%s"'), $name); - } - } else { - return sprintf(_('Unknown field "%s"'), $name); - } - } - return TRUE; - } - - /* Returns TRUE if this attribute should be asked in the creation by template dialog */ - function showInTemplate($attr, $templateAttrs) - { - if (isset($templateAttrs[$attr])) { - return FALSE; - } - return TRUE; - } } - ?> diff --git a/include/simpleplugin/class_simpleTabs.inc b/include/simpleplugin/class_simpleTabs.inc index 2f4df1603..8fc27d504 100644 --- a/include/simpleplugin/class_simpleTabs.inc +++ b/include/simpleplugin/class_simpleTabs.inc @@ -51,49 +51,30 @@ class simpleTabs /*! * \brief Tabs classes constructor - * - * You should either call __construct($type, $dn, [$copied_object]) or (deprecated) __construct(NULL, $data, $dn, $category, [$copied_object]) * */ - function __construct() + function __construct($type, $dn, $attrs_object = NULL) { global $config; - $attrs_object = NULL; - if (is_string(func_get_arg(0))) { - $type = func_get_arg(0); - $dn = func_get_arg(1); - $infos = objects::infos($type); - - $data = $config->data['TABS'][$infos['tabGroup']]; - $acl_category = $infos['aclCategory']; - if (func_num_args() >= 3) { - $attrs_object = func_get_arg(2); - } - $this->objectType = $type; - } else { - trigger_error('deprecated call to old tabclass constructor'); - /* Deprecated, used by old management classes */ - //$config_object = func_get_arg(0); // ignored - $data = func_get_arg(1); - $dn = func_get_arg(2); - $acl_category = func_get_arg(3); - if (func_num_args() >= 5) { - $attrs_object = func_get_arg(4); - } + + if (!is_string($type)) { + die('deprecated call to old tabclass constructor'); } - /* Save dn */ - $this->dn = $dn; + $infos = objects::infos($type); + $data = $config->data['TABS'][$infos['tabGroup']]; + $this->acl_category = $infos['aclCategory']; + $this->objectType = $type; + $this->dn = $dn; if (!count($data)) { - $data[] = array("CLASS" => 'plugin',"NAME" => 'Error'); - msg_dialog::display(_("Error"), - sprintf(_("No plugin definitions found to initialize '%s', please check your configuration file."), get_class($this)), + $data[] = array('CLASS' => 'plugin','NAME' => 'Error'); + msg_dialog::display(_('Error'), + sprintf(_('No plugin definitions found to initialize "%s", please check your configuration file.'), get_class($this)), ERROR_DIALOG); } $baseobject = NULL; - $this->acl_category = $acl_category; - foreach ($data as &$tab) { + foreach ($data as $tab) { if (!plugin_available($tab['CLASS'])) { continue; } @@ -111,15 +92,16 @@ class simpleTabs $this->read_only |= $this->by_object[$tab['CLASS']]->read_only; $this->by_object[$tab['CLASS']]->set_acl_category($this->acl_category); } - unset($tab); /* Initialize current */ $this->current = $this->baseclass; - $infos = $this->objectInfos(); - if ($infos && $infos['mainAttr']) { + if ($infos['mainAttr']) { $baseobject = $this->getBaseObject(); - if (($baseobject instanceof simplePlugin) && $baseobject->attributesAccess[$infos['mainAttr']]->getUnique() === FALSE) { + if ( + ($baseobject instanceof simplePlugin) && + ($baseobject->attributesAccess[$infos['mainAttr']]->getUnique() === FALSE) + ) { $baseobject->attributesAccess[$infos['mainAttr']]->setUnique(TRUE); } } -- GitLab