reduced upload code

This commit is contained in:
Roland Gruber 2014-04-13 10:50:59 +00:00
parent 6d726b9a4c
commit 4c38fa8564
2 changed files with 42 additions and 81 deletions

View File

@ -5,7 +5,7 @@
This code is part of LDAP Account Manager (http://www.sourceforge.net/projects/lam) This code is part of LDAP Account Manager (http://www.sourceforge.net/projects/lam)
Copyright (C) 2009 - 2012 Pavel Pozdniak Copyright (C) 2009 - 2012 Pavel Pozdniak
2009 - 2012 Roland Gruber 2009 - 2014 Roland Gruber
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -845,16 +845,16 @@ class asteriskExtension extends baseModule {
$messages = array(); $messages = array();
//hash to strore extension_name => priority. For new extensoin priority will be 1 //hash to strore extension_name => priority. For new extensoin priority will be 1
$extensionNamePriorityMap = array(); $extensionNamePriorityMap = array();
for ($rawAccIdx = 0; $rawAccIdx < sizeof($rawAccounts); $rawAccIdx++) { for ($i = 0; $i < sizeof($rawAccounts); $i++) {
// add object class // add object class
if (!in_array("AsteriskExtension", $partialAccounts[$rawAccIdx]['objectClass'])) if (!in_array("AsteriskExtension", $partialAccounts[$i]['objectClass']))
$partialAccounts[$rawAccIdx]['objectClass'][] = "AsteriskExtension"; $partialAccounts[$i]['objectClass'][] = "AsteriskExtension";
if (!in_array("groupOfNames", $partialAccounts[$rawAccIdx]['objectClass'])) if (!in_array("groupOfNames", $partialAccounts[$i]['objectClass']))
$partialAccounts[$rawAccIdx]['objectClass'][] = "groupOfNames"; $partialAccounts[$i]['objectClass'][] = "groupOfNames";
// attributes // attributes
$partialAccounts[$rawAccIdx]['AstExtension'] = $rawAccounts[$rawAccIdx][$ids['asteriskExtension_AstExtension']]; $partialAccounts[$i]['AstExtension'] = $rawAccounts[$i][$ids['asteriskExtension_AstExtension']];
$extensionName = $partialAccounts[$rawAccIdx]['AstExtension']; $extensionName = $partialAccounts[$i]['AstExtension'];
$astPriorityTmp = 0; $astPriorityTmp = 0;
if(isset ($extensionNamePriorityMap[$extensionName])){ if(isset ($extensionNamePriorityMap[$extensionName])){
$astPriorityTmp = $extensionNamePriorityMap[$extensionName] + 1; $astPriorityTmp = $extensionNamePriorityMap[$extensionName] + 1;
@ -863,25 +863,19 @@ class asteriskExtension extends baseModule {
$astPriorityTmp = 1; $astPriorityTmp = 1;
$extensionNamePriorityMap[$extensionName] = $astPriorityTmp; $extensionNamePriorityMap[$extensionName] = $astPriorityTmp;
} }
$partialAccounts[$rawAccIdx]['AstPriority'] = $astPriorityTmp; $partialAccounts[$i]['AstPriority'] = $astPriorityTmp;
$partialAccounts[$rawAccIdx]['cn'] = $extensionName . '-' . $astPriorityTmp; $partialAccounts[$i]['cn'] = $extensionName . '-' . $astPriorityTmp;
if(isset($rawAccounts[$rawAccIdx][$ids['asteriskExtension_owner']]) && $rawAccounts[$rawAccIdx][$ids['asteriskExtension_owner']] != '' ){ if (isset($rawAccounts[$i][$ids['asteriskExtension_owner']]) && $rawAccounts[$i][$ids['asteriskExtension_owner']] != '' ) {
$partialAccounts[$rawAccIdx]['member'] = explode(';', $rawAccounts[$rawAccIdx][$ids['asteriskExtension_owner']]); $partialAccounts[$i]['member'] = explode(';', $rawAccounts[$i][$ids['asteriskExtension_owner']]);
}else{ } else {
$partialAccounts[$rawAccIdx]['member'] = $this->getDefaultExtensionOwner(); $partialAccounts[$i]['member'] = $this->getDefaultExtensionOwner();
}
if ($rawAccounts[$rawAccIdx][$ids['asteriskExtension_AstApplication']] != "") {
$partialAccounts[$rawAccIdx]['AstApplication'] = $rawAccounts[$rawAccIdx][$ids['asteriskExtension_AstApplication']];
}
if (isset($rawAccounts[$rawAccIdx][$ids['asteriskExtension_AstApplicationData']])
&& $rawAccounts[$rawAccIdx][$ids['asteriskExtension_AstApplicationData']] != "") {
$partialAccounts[$rawAccIdx]['AstApplicationData'] = $rawAccounts[$rawAccIdx][$ids['asteriskExtension_AstApplicationData']];
}
if ($rawAccounts[$rawAccIdx][$ids['asteriskExtension_AstContext']] != "") {
$partialAccounts[$rawAccIdx]['AstContext'] = $rawAccounts[$rawAccIdx][$ids['asteriskExtension_AstContext']];
} }
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'asteriskExtension_AstApplication', 'AstApplication');
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'asteriskExtension_AstApplicationData', 'AstApplicationData');
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'asteriskExtension_AstContext', 'AstContext');
} }
return $messages; return $messages;

View File

@ -4,7 +4,7 @@ $Id$
This code is part of LDAP Account Manager (http://www.sourceforge.net/projects/lam) This code is part of LDAP Account Manager (http://www.sourceforge.net/projects/lam)
Copyright (C) 2010 Pavel Pozdnyak Copyright (C) 2010 Pavel Pozdnyak
2010 - 2013 Roland Gruber 2010 - 2014 Roland Gruber
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -202,14 +202,18 @@ class asteriskVoicemail extends baseModule implements passwordService {
$this->messages['AstVoicemailMailbox'][0] = array('ERROR', _('Please enter a mailbox.')); $this->messages['AstVoicemailMailbox'][0] = array('ERROR', _('Please enter a mailbox.'));
$this->messages['AstVoicemailMailbox'][1] = array('ERROR', _('The mailbox format is invalid.')); $this->messages['AstVoicemailMailbox'][1] = array('ERROR', _('The mailbox format is invalid.'));
$this->messages['AstVoicemailMailbox'][2] = array('ERROR', _('There is already another user with this mailbox name.')); $this->messages['AstVoicemailMailbox'][2] = array('ERROR', _('There is already another user with this mailbox name.'));
$this->messages['AstVoicemailMailbox'][3] = array('ERROR', _('Account %s:') . ' asteriskVoicemail_AstVoicemailMailbox', _('The mailbox format is invalid.'));
$this->messages['AstContext'][0] = array('ERROR', _('Please enter the account context.')); $this->messages['AstContext'][0] = array('ERROR', _('Please enter the account context.'));
$this->messages['AstContext'][1] = array('ERROR', _('The account context is invalid.')); $this->messages['AstContext'][1] = array('ERROR', _('The account context is invalid.'));
$this->messages['AstContext'][2] = array('ERROR', _('Account %s:') . ' asteriskVoicemail_AstContext', _('The account context is invalid.')); $this->messages['AstContext'][2] = array('ERROR', _('Account %s:') . ' asteriskVoicemail_AstContext', _('The account context is invalid.'));
$this->messages['AstVoicemailFullname'][0] = array('ERROR', _('The full name is invalid.')); $this->messages['AstVoicemailFullname'][0] = array('ERROR', _('The full name is invalid.'));
$this->messages['AstVoicemailEmail'][01] = array('ERROR', _('The email address is invalid.')); $this->messages['AstVoicemailFullname'][1] = array('ERROR', _('Account %s:') . ' asteriskVoicemail_AstVoicemailFullname', _('The full name is invalid.'));
$this->messages['AstVoicemailEmail'][0] = array('ERROR', _('The email address is invalid.'));
$this->messages['AstVoicemailEmail'][1] = array('ERROR', _('Account %s:') . ' asteriskVoicemail_AstVoicemailEmail', _('The email address is invalid.'));
$this->messages['AstVoicemailPager'][0] = array('ERROR', _('The pager number has bad format.')); $this->messages['AstVoicemailPager'][0] = array('ERROR', _('The pager number has bad format.'));
$this->messages['AstVoicemailPager'][1] = array('ERROR', _('Account %s:') . ' asteriskVoicemail_AstVoicemailPager', _('The pager number has bad format.'));
$this->messages['AstVoicemailOptions'][0] = array('ERROR', _('The options have bad format.')); $this->messages['AstVoicemailOptions'][0] = array('ERROR', _('The options have bad format.'));
$this->messages['AstVoicemailOptions'][1] = array('ERROR', _('Account %s:') . ' asteriskVoicemail_AstVoicemailOptions', _('The options have bad format.')); $this->messages['AstVoicemailOptions'][1] = array('ERROR', _('Account %s:') . ' asteriskVoicemail_AstVoicemailOptions', _('The options have bad format.'));
$this->messages['AstVoicemailContext'][0] = array('ERROR', _('The voicemail context name is invalid.')); $this->messages['AstVoicemailContext'][0] = array('ERROR', _('The voicemail context name is invalid.'));
@ -381,68 +385,31 @@ class asteriskVoicemail extends baseModule implements passwordService {
if (!in_array("AsteriskVoiceMail", $partialAccounts[$i]['objectClass'])) $partialAccounts[$i]['objectClass'][] = "AsteriskVoiceMail"; if (!in_array("AsteriskVoiceMail", $partialAccounts[$i]['objectClass'])) $partialAccounts[$i]['objectClass'][] = "AsteriskVoiceMail";
//add context //add context
if ($rawAccounts[$i][$ids['asteriskVoicemail_AstContext']] == "") { if (empty($rawAccounts[$i][$ids['asteriskVoicemail_AstContext']])) {
// default value // default value
$partialAccounts[$i]['AstContext'] = 'default'; $partialAccounts[$i]['AstContext'] = 'default';
} }
elseif (get_preg($rawAccounts[$i][$ids['asteriskVoicemail_AstContext']], 'realname')) {
$partialAccounts[$i]['AstContext'] = $rawAccounts[$i][$ids['asteriskVoicemail_AstContext']];
}
else { else {
$errMsg = $this->messages['AstContext'][2]; $this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'asteriskVoicemail_AstContext', 'AstContext',
array_push($errMsg, array($i)); 'realname', $this->messages['AstContext'][2], $messages);
$messages[] = $errMsg;
} }
// add account caller id $this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'asteriskVoicemail_AstVoicemailMailbox', 'AstVoicemailMailbox',
if (get_preg($rawAccounts[$i][$ids['asteriskVoicemail_AstVoicemailMailbox']], 'realname')) { 'realname', $this->messages['AstVoicemailMailbox'][3], $messages);
$partialAccounts[$i]['AstVoicemailMailbox'] = $rawAccounts[$i][$ids['asteriskVoicemail_AstVoicemailMailbox']];
}
else {
$errMsg = $this->messages['AstVoicemailMailbox'][1];
array_push($errMsg, array($i));
$messages[] = $errMsg;
}
if (get_preg($rawAccounts[$i][$ids['asteriskVoicemail_AstVoicemailEmail']], 'email')) { $this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'asteriskVoicemail_AstVoicemailEmail', 'AstVoicemailEmail',
$partialAccounts[$i]['AstVoicemailEmail'] = $rawAccounts[$i][$ids['asteriskVoicemail_AstVoicemailEmail']]; 'email', $this->messages['AstVoicemailEmail'][1], $messages);
}
else {
$errMsg = $this->messages['AstVoicemailEmail'][1];
array_push($errMsg, array($i));
$messages[] = $errMsg;
}
if (get_preg($rawAccounts[$i][$ids['asteriskVoicemail_AstVoicemailPager']], 'telephone')) { $this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'asteriskVoicemail_AstVoicemailPager', 'AstVoicemailPager',
$partialAccounts[$i]['AstVoicemailPager'] = $rawAccounts[$i][$ids['asteriskVoicemail_AstVoicemailPager']]; 'telephone', $this->messages['AstVoicemailPager'][1], $messages);
}
else {
$errMsg = $this->messages['AstVoicemailPager'][1];
array_push($errMsg, array($i));
$messages[] = $errMsg;
}
if ($rawAccounts[$i][$ids['asteriskVoicemail_AstVoicemailOptions']]!= "") { $this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'asteriskVoicemail_AstVoicemailOptions', 'AstVoicemailOptions');
$partialAccounts[$i]['AstVoicemailOptions'] = $rawAccounts[$i][$ids['asteriskVoicemail_AstVoicemailOptions']];
}
if (($rawAccounts[$i][$ids['asteriskVoicemail_AstVoicemailFullname']] != "") && (get_preg($rawAccounts[$i][$ids['asteriskVoicemail_AstVoicemailFullname']], 'realname')) ) { $this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'asteriskVoicemail_AstVoicemailFullname', 'AstVoicemailFullname',
$partialAccounts[$i]['AstVoicemailFullname'] = $rawAccounts[$i][$ids['asteriskVoicemail_AstVoicemailFullname']]; 'realname', $this->messages['AstVoicemailFullname'][1], $messages);
}
else {
$errMsg = $this->messages['AstVoicemailFullname'][0];
array_push($errMsg, array($i));
$messages[] = $errMsg;
}
if (($rawAccounts[$i][$ids['asteriskVoicemail_AstVoicemailContext']] != "") && (get_preg($rawAccounts[$i][$ids['asteriskVoicemail_AstVoicemailContext']], 'realname')) ) { $this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'asteriskVoicemail_AstVoicemailContext', 'AstVoicemailContext',
$partialAccounts[$i]['AstVoicemailContext'] = $rawAccounts[$i][$ids['asteriskVoicemail_AstVoicemailContext']]; 'realname', $this->messages['AstVoicemailContext'][1], $messages);
}
else {
$errMsg = $this->messages['AstVoicemailContext'][1];
array_push($errMsg, array($i));
$messages[] = $errMsg;
}
$partialAccounts[$i]['AstVoicemailPassword'] = $rawAccounts[$i][$ids['asteriskVoicemail_AstVoicemailPassword']]; $partialAccounts[$i]['AstVoicemailPassword'] = $rawAccounts[$i][$ids['asteriskVoicemail_AstVoicemailPassword']];
} }