Commit 21854a0a authored by Côme Chilliet's avatar Côme Chilliet
Browse files

Removed unused parameters, added curly braces

parent 483b0d7f
......@@ -486,7 +486,7 @@ class Index {
);
exit();
}
$ui = new userinfo($config, $attrs['dn']);
$ui = new userinfo($attrs['dn']);
$ui->loadACL();
$success = static::runSteps(array(
......@@ -558,7 +558,7 @@ class Index {
);
exit();
}
$ui = new userinfo($config, $attrs['dn']);
$ui = new userinfo($attrs['dn']);
$ui->loadACL();
$success = static::runSteps(array(
......
......@@ -578,25 +578,31 @@ class LDAP
function rm($attrs = "", $dn = "")
{
if ($this->hascon) {
if ($this->reconnect) $this->connect();
if ($dn == "")
if ($this->reconnect) {
$this->connect();
}
if ($dn == '') {
$dn = $this->basedn;
}
$r = ldap_mod_del($this->cid, LDAP::fix($dn), $attrs);
$this->error = @ldap_error($this->cid);
return $r;
} else {
$this->error = "Could not connect to LDAP server";
return "";
$this->error = 'Could not connect to LDAP server';
return '';
}
}
function mod_add($attrs = "", $dn = "")
{
if ($this->hascon) {
if ($this->reconnect) $this->connect();
if ($dn == "")
if ($this->reconnect) {
$this->connect();
}
if ($dn == "") {
$dn = $this->basedn;
}
$r = @ldap_mod_add($this->cid, LDAP::fix($dn), $attrs);
$this->error = @ldap_error($this->cid);
......@@ -615,7 +621,9 @@ class LDAP
function rmdir($deletedn)
{
if ($this->hascon) {
if ($this->reconnect) $this->connect();
if ($this->reconnect) {
$this->connect();
}
$r = @ldap_delete($this->cid, LDAP::fix($deletedn));
$this->error = @ldap_error($this->cid);
return ($r ? $r : 0);
......@@ -660,7 +668,9 @@ class LDAP
$dest_rdn = preg_replace("/,.*$/", "", $dest);
if ($this->hascon) {
if ($this->reconnect) $this->connect();
if ($this->reconnect) {
$this->connect();
}
$r = ldap_rename($this->cid, @LDAP::fix($source), @LDAP::fix($dest_rdn), @LDAP::fix($parent), FALSE);
$this->error = ldap_error($this->cid);
......@@ -689,7 +699,9 @@ class LDAP
function rmdir_recursive($srp, $deletedn)
{
if ($this->hascon) {
if ($this->reconnect) $this->connect();
if ($this->reconnect) {
$this->connect();
}
$delarray = array();
/* Get sorted list of dn's to delete */
......@@ -749,7 +761,9 @@ class LDAP
return 0;
}
if ($this->hascon) {
if ($this->reconnect) $this->connect();
if ($this->reconnect) {
$this->connect();
}
$r = @ldap_modify($this->cid, LDAP::fix($this->basedn), $attrs);
$this->error = @ldap_error($this->cid);
if (!$this->success()) {
......@@ -770,7 +784,9 @@ class LDAP
function add($attrs)
{
if ($this->hascon) {
if ($this->reconnect) $this->connect();
if ($this->reconnect) {
$this->connect();
}
$r = @ldap_add($this->cid, LDAP::fix($this->basedn), $attrs);
$this->error = @ldap_error($this->cid);
if (!$this->success()) {
......@@ -875,7 +891,9 @@ class LDAP
// Fill in MUST values - but do not overwrite existing ones.
if (is_array($classes[$ocname]['MUST'])) {
foreach ($classes[$ocname]['MUST'] as $attr) {
if (isset($na[$attr]) && !empty($na[$attr])) continue;
if (isset($na[$attr]) && !empty($na[$attr])) {
continue;
}
$na[$attr] = 'filled';
}
}
......
......@@ -1050,7 +1050,7 @@ class listing {
$cut = !isset($action['cut']) || $action['cut'] == "true";
$result .= $this->renderCopyPasteActions($row, $this->entries[$row]['dn'], $category, $class, $copy, $cut);
} else {
$result .= $this->renderSnapshotActions($row, $this->entries[$row]['dn'], $category, $class);
$result .= $this->renderSnapshotActions($row, $this->entries[$row]['dn'], $category);
}
}
}
......@@ -1639,7 +1639,7 @@ class listing {
// Render copy entries
if ($copy) {
if ($ui->is_copyable($dn, $category, $class)) {
if ($ui->is_copyable($dn, $category)) {
$result .= '<input class="center" type="image"'.
' src="geticon.php?context=actions&amp;icon=edit-copy&amp;size=16"'.
' alt="'._('Copy').'" name="listing_copy_'.$row.'" title="'._('Copy this entry').'"'.
......@@ -1705,44 +1705,43 @@ class listing {
}
function renderSnapshotActions($row, $dn, $category, $class, $copy = TRUE, $cut = TRUE)
function renderSnapshotActions($row, $dn, $category)
{
// We can only provide information if we've got a snapshot handler
// instance
if (!(isset($this->snapshotHandler) && is_object($this->snapshotHandler))) {
return "";
/* We can only provide information if we've got a snapshot handler instance */
if (!isset($this->snapshotHandler) || !is_object($this->snapshotHandler) || !$this->snapshotHandler->enabled()) {
return '';
}
// Presets
$result = "";
$result = '';
$ui = get_userinfo();
// Only act if enabled here
if ($this->snapshotHandler->enabled()) {
// Draw restore button
if ($ui->allow_snapshot_restore($dn, $category)) {
// Do we have snapshots for this dn?
if ($this->snapshotHandler->hasSnapshots($dn)) {
$result .= "<input class='center' type='image' src='geticon.php?context=actions&amp;icon=document-restore&amp;size=16' ".
"alt='"._("Restore snapshot")."' name='listing_restore_$row' title='".
_("Restore snapshot")."' style='padding:1px'>";
} else {
$result .= "<img src='geticon.php?context=actions&amp;icon=document-restore&amp;size=16&amp;disabled=1' alt='restore' class='center' style='padding:1px'>";
}
}
if ($ui->allow_snapshot_restore($dn, $category)) {
/* Draw restore button */
// Draw snapshot button
if ($ui->allow_snapshot_create($dn, $category)) {
$result .= "<input class='center' type='image' src='geticon.php?context=actions&amp;icon=snapshot&amp;size=16' ".
"alt='"._("Create snapshot")."' name='listing_snapshot_$row' title='".
_("Create a new snapshot from this object")."' style='padding:1px'>";
if ($this->snapshotHandler->hasSnapshots($dn)) {
/* We have snapshots for this dn */
$result .= '<input class="center" type="image"'.
' src="geticon.php?context=actions&amp;icon=document-restore&amp;size=16"'.
' alt="'._('Restore snapshot').'" name="listing_restore_'.$row.'"'.
' title="'._('Restore snapshot').'" style="padding:1px"/>';
} else {
$result .= "<img src='images/empty.png' alt=' ' class='center optional' style='padding:1px'>";
$result .= '<img class="center"'.
' src="geticon.php?context=actions&amp;icon=document-restore&amp;size=16&amp;disabled=1"'.
' alt="restore" style="padding:1px"/>';
}
}
if ($ui->allow_snapshot_create($dn, $category)) {
/* Draw snapshot button */
$result .= '<input class="center" type="image"'.
' src="geticon.php?context=actions&amp;icon=snapshot&amp;size=16"'.
' alt="'._('Create snapshot').'" name="listing_snapshot_'.$row.'"'.
' title="'._('Create a new snapshot from this object').'" style="padding:1px"/>';
} else {
$result .= '<img src="images/empty.png" alt=" " class="center optional" style="padding:1px"/>';
}
return $result;
}
......
......@@ -190,7 +190,9 @@ class management
}
// No bases specified? Try base
if (!count($bases)) $bases[] = $this->headpage->getBase();
if (!count($bases)) {
$bases[] = $this->headpage->getBase();
}
$this->snapHandler->setSnapshotBases($bases);
}
......@@ -284,9 +286,13 @@ class management
return array();
}
$action = $this->headpage->getAction();
if (isset($_POST['edit_apply'])) $action['action'] = 'apply';
if (isset($_POST['edit_finish'])) $action['action'] = 'save';
if (isset($_POST['edit_cancel'])) $action['action'] = 'cancel';
if (isset($_POST['edit_cancel'])) {
$action['action'] = 'cancel';
} elseif (isset($_POST['edit_finish'])) {
$action['action'] = 'save';
} elseif (isset($_POST['edit_apply'])) {
$action['action'] = 'apply';
}
if (!$this->is_modal_dialog()) {
if (isset($_POST['delete_confirmed'])) {
$action['action'] = 'removeConfirmed';
......
......@@ -522,17 +522,17 @@ class msgPool {
*
* \param string $what Text for the button
*/
public static function editButton($what = "")
public static function editButton($what = '')
{
return ($what == "" ? sprintf(_("Edit...")): sprintf(_("Edit %s..."), $what));
return (($what == '') ? sprintf(_('Edit...')) : sprintf(_('Edit %s...'), $what));
}
/*!
* \brief Text for a back button
*/
public static function backButton($what = "")
public static function backButton()
{
return _("Back");
return _('Back');
}
/*!
......@@ -668,20 +668,6 @@ class msgPool {
return array( _("Sunday"), _("Monday"), _("Tuesday"), _("Wednesday"), _("Thursday"), _("Friday"), _("Saturday"));
}
/*!
* \brief Display error about database
*
* \param string $error Error to display
*
* \param string $plugin
*/
public static function dbError($error, $plugin = "")
{
/* Assign headline depending on type */
$headline = _("Database operation failed!");
return $headline."<br><br><i>"._("Error").":</i> ".$error;
}
/*!
* \brief Display LDAP error
*
......@@ -693,24 +679,24 @@ class msgPool {
*
* \param string $plugin
*/
public static function ldaperror($error, $dn = "", $type = 0, $plugin = "")
public static function ldaperror($error, $dn = '', $type = 0, $plugin = '')
{
/* Assign headline depending on type */
$typemap = array(1 => _("read operation"), _("add operation"), _("modify operation"),
_("delete operation"), _("search operation"), _("authentication"));
$typemap = array(1 => _('read operation'), _('add operation'), _('modify operation'),
_('delete operation'), _('search operation'), _('authentication'));
if (isset($typemap[$type])) {
$headline = sprintf(_("LDAP %s failed!"), $typemap[$type]);
$headline = sprintf(_('LDAP %s failed!'), $typemap[$type]);
} else {
$headline = _("LDAP operation failed!");
$headline = _('LDAP operation failed!');
}
/* Fill DN information */
if ($dn != "") {
$dn_info = "<br><br><i>"._("Object").":</i> ".LDAP::fix($dn);
if ($dn != '') {
$dn_info = '<br/><br/><i>'._('Object').':</i> '.LDAP::fix($dn);
}
return $headline.$dn_info."<br><br><i>"._("Error").":</i> ".$error;
return $headline.$dn_info.'<br/><br/><i>'._('Error').':</i> '.$error;
}
/*!
......
......@@ -1165,10 +1165,8 @@ class plugin
* \param string $old_dn specifies the actually used dn
*
* \param string $new_dn specifies the destiantion dn
*
* \param boolean $output_changes FALSE
*/
function update_acls($old_dn, $new_dn, $output_changes = FALSE)
function update_acls($old_dn, $new_dn)
{
/* Check if old_dn is empty. This should never happen */
if (empty($old_dn) || empty($new_dn)) {
......
......@@ -225,7 +225,7 @@ class pluglist {
return TRUE;
}
} else {
if ($ui->get_category_permissions($ui->dn, $acl_to_check, "") != "") {
if ($ui->get_category_permissions($ui->dn, $acl_to_check) != '') {
$this->silly_cache[$aclname] = TRUE;
return TRUE;
}
......
......@@ -265,10 +265,8 @@ class tests {
* \brief Check if the given argument is an email
*
* \param string $address The email address
*
* \param boolean $template FALSE
*/
public static function is_email($address, $deprecated = FALSE)
public static function is_email($address)
{
if ($address == "") {
return TRUE;
......
......@@ -52,7 +52,7 @@ class userinfo
/* get acl's an put them into the userinfo object
attr subtreeACL (userdn:components, userdn:component1#sub1#sub2,component2,...) */
function __construct($unused, $userdn)
function __construct($userdn)
{
global $config;
$ldap = $config->get_ldap_link();
......@@ -284,13 +284,11 @@ class userinfo
*
* \param string $category Category for which we want the acl eg: server
*
* \param bool $any_acl FALSE
*
* \return all the permissions for the dn and category
*/
function get_category_permissions($dn, $category, $any_acl = FALSE)
function get_category_permissions($dn, $category)
{
return @$this->get_permissions($dn, $category.'/0', "");
return @$this->get_permissions($dn, $category.'/0', '');
}
......@@ -301,13 +299,11 @@ class userinfo
*
* \param string $object The acl category (e.g. user)
*
* \param string $class The acl class (e.g. user)
*
* \return boolean TRUE if the given object is copyable else FALSE
*/
function is_copyable($dn, $object, $class)
function is_copyable($dn, $object)
{
return preg_match("/r/", $this->get_complete_category_acls($dn, $object));
return preg_match('/r/', $this->get_complete_category_acls($dn, $object));
}
......@@ -666,12 +662,14 @@ class userinfo
/* For all gosaDepartments */
foreach ($config->departments as $dn) {
if (isset($deps[$dn])) continue;
$acl = "";
if (isset($deps[$dn])) {
continue;
}
$acl = '';
if (strpos($mod, '/')) {
$acl .= $this->get_permissions($dn, $mod);
} else {
$acl .= $this->get_category_permissions($dn, $mod, TRUE);
$acl .= $this->get_category_permissions($dn, $mod);
}
if (!empty($acl)) {
$deps[$dn] = $dn;
......@@ -792,8 +790,10 @@ class userinfo
if (!isset($this->result_cache['get_complete_category_acls'][$dn][$category])) {
if (isset($config->data['CATEGORIES'][$category])) {
foreach ($config->data['CATEGORIES'][$category]['classes'] as $oc) {
/* Skip objectClass '0' (e.g. user/0) get_permissions will ever return '' ?? */
if ($oc == "0") continue;
if ($oc == '0') {
/* Skip objectClass '0' (e.g. user/0) get_permissions will ever return '' ?? */
continue;
}
$tmp = $this->get_permissions($dn, $category."/".$oc);
for ($i = 0, $l = strlen($types); $i < $l; $i++) {
if (!preg_match("/".$types[$i]."/", $tmp)) {
......
......@@ -576,7 +576,7 @@ function ldap_login_user ($username, $password)
}
/* got user dn, fill acl's */
$ui = new userinfo($config, $ldap->getDN());
$ui = new userinfo($ldap->getDN());
/* password check, bind as user with supplied password */
$ldap->disconnect();
......
......@@ -333,7 +333,9 @@ function show_vars($show_all_vars = FALSE, $show_object_vars = FALSE)
}
foreach ($vars_arr as $vars_name => $vars_data) {
if ($vars_name != 'script_globals') global $$vars_name;
if ($vars_name != 'script_globals') {
global $$vars_name;
}
if ($$vars_name) {
print '<div class="vars-container" style="background-color:'.$vars_data[1].';"><span class="varsname">'.$vars_data[0].'</span><br />';
print_a($$vars_name, FALSE, $show_object_vars, FALSE );
......
......@@ -18,31 +18,14 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*! \brief This class allow to handle easily a String LDAP attribute that contains a mail address
*
*/
class MailAttribute extends StringAttribute
{
private $template;
/*! \brief The constructor of MailAttribute
*
* \param string $label The label to show for this attribute
* \param string $description A more detailed description for the attribute
* \param string $ldapName The name of the attribute in the LDAP (If it's not in the ldap, still provide a unique name)
* \param boolean $required Is this attribute mandatory or not
* \param mixed $defaultValue The default value for this attribute
* \param string $acl The name of the acl for this attribute if he does not use its own. (Leave empty if he should use its own like most attributes do)
* \param boolean $template Should this email field accept template character '%' ?
*/
function __construct ($label, $description, $ldapName, $required = FALSE, $defaultValue = "", $acl = "", $template = FALSE)
{
parent::__construct($label, $description, $ldapName, $required, $defaultValue, $acl);
$this->template = $template;
}
function validate ()
{
if (!tests::is_email($this->value, $this->template)) {
if (!tests::is_email($this->value)) {
return msgPool::invalid($this->getLabel(), $this->value);
}
}
......
......@@ -854,7 +854,7 @@ class simpleManagement extends management
}
$infos = objects::infos($type);
if ($action == "copy" && $ui->is_copyable($dn, $infos['aclCategory'], $infos['mainTab'])) {
if ($action == "copy" && $ui->is_copyable($dn, $infos['aclCategory'])) {
$this->cpHandler->add_to_queue($dn, "copy", $type);
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $dn, "Entry copied!");
}
......
......@@ -66,7 +66,7 @@ class Step_Finish extends setupStep
/* Create ui object */
/* got user dn, fill acl's */
$ui = new userinfo($config, $cv['valid_admin']);
$ui = new userinfo($cv['valid_admin']);
/* Username is set, load subtreeACL's now */
$ui->loadACL();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment