summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: bffbf30)
raw | patch | inline | side by side (parent: bffbf30)
author | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Mon, 27 Jun 2011 12:09:58 +0000 (12:09 +0000) | ||
committer | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Mon, 27 Jun 2011 12:09:58 +0000 (12:09 +0000) |
-Allow to leave uid blank for csv imports
git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.6@20919 594d385d-05f5-0310-b6e9-bd551577e9d8
git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.6@20919 594d385d-05f5-0310-b6e9-bd551577e9d8
gosa-plugins/ldapmanager/addons/ldapmanager/class_csvimport.inc | patch | blob | history | |
gosa-plugins/ldapmanager/addons/ldapmanager/contentcsv.tpl | patch | blob | history |
diff --git a/gosa-plugins/ldapmanager/addons/ldapmanager/class_csvimport.inc b/gosa-plugins/ldapmanager/addons/ldapmanager/class_csvimport.inc
index fb0c41db20615eac6009535d0c206d2564650d1d..c56d6b245d9ca62dc9a7335295980b7ebf133cdb 100644 (file)
$dat = $this->csvinfo['sorteddata'][$i];
/* If not all needed vars set .... */
- if(( empty($dat['sn']))||( empty($dat['givenName']))||( empty($dat['uid']))||
- (!isset($dat['sn']))||(!isset($dat['givenName']))||(!isset($dat['uid']))){
+ if(!isset($dat['givenName']) || empty($dat['givenName']) || !isset($dat['sn']) || empty($dat['sn'])){
/* Output Error */
- msg_dialog::display(_("Error"), _("Need at least 'sn', 'givenName' and 'uid' to create users."), ERROR_DIALOG);
- } else {
+ msg_dialog::display(_("Error"), _("Need at least 'sn' and 'givenName' to create users!"), ERROR_DIALOG);
+ $this->csvinfo['sorteddata'][$i]['status']="<b>"._("failed")."</b>";
+ $failing = $i+1;
+ continue;
+ }
+
+ /* Automatically generate 'uid' while it wasn't given yet.
+ */
+ if(!isset($dat['uid']) || empty($dat['uid'])){
+
+ // Generate uids and take the first result.
+ $attributes= array('sn' => $dat['sn'], 'givenName' => $dat['givenName']);
+ $uids = gen_uids ($this->config->get_cfg_value("idGenerator"), $attributes);
+ if (!count($uids) || empty($uids[0])){
+ $msgs = sprintf(_("Failed to generate 'uid' for entry '%s'!"), ($i+1));
+ $this->csvinfo['sorteddata'][$i]['status']="<b>"._("failed")."</b> ". $msgs;
+ $failing = $i+1;
+ continue;
+ }else{
+ $this->csvinfo['sorteddata'][$i]['uid'] = array_pop($uids);
+ $dat['uid'] = $this->csvinfo['sorteddata'][$i]['uid'];
+ }
+ }
- /* Register usertab to trigger edit dialog */
- $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'], 'new');
- $keys = array_keys($dat);
-
- /* Set all submitted vars */
- if(is_array($keys)){
- foreach($keys as $key) {
- if($key != "status"){
- $this->usertab->$key = $dat[$key];
- foreach($this->usertab->by_object as $pname => $plugin){
- if(isset($this->usertab->by_object[$pname]->$key)){
- $this->usertab->by_object[$pname]->$key = $dat[$key];
- }
+ /* Register usertab to trigger edit dialog */
+ $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'], 'new');
+ $keys = array_keys($dat);
+
+ /* Set all submitted vars */
+ if(is_array($keys)){
+ foreach($keys as $key) {
+ if($key != "status"){
+ $this->usertab->$key = $dat[$key];
+ foreach($this->usertab->by_object as $pname => $plugin){
+ if(isset($this->usertab->by_object[$pname]->$key)){
+ $this->usertab->by_object[$pname]->$key = $dat[$key];
}
}
}
}
+ }
- // Adapt template values.
- if($this->csvinfo['tplid']!=0){
- $tpl_dn = $this->csvinfo['arrtempls'][$this->csvinfo['tplid']]['dn'];
- $this->usertab->adapt_from_template($tpl_dn,array("uid","cn","givenName","sn"));
- $tpl_base = preg_replace("/^[^,]+,".preg_quote(get_people_ou(), '/i')."/", '', $tpl_dn);
- $this->usertab->by_object['user']->base= $tpl_base;
- }
-
- // Setting user Password
- if((isset($dat['userPassword']))&&(!empty($dat['userPassword']))){
- $password = $dat['userPassword'];
- }else{
- $rand_str="";
- $feed = "0123456789abcdefghijklmnopqrstuvwxyz";
- for ($e=0; $e < 8; $e++)
- {
- $rand_str .= substr($feed, rand(0, strlen($feed)-1), 1);
- }
- $password = $rand_str;
+ // Adapt template values.
+ if($this->csvinfo['tplid']!=0){
+ $tpl_dn = $this->csvinfo['arrtempls'][$this->csvinfo['tplid']]['dn'];
+ $this->usertab->adapt_from_template($tpl_dn,array("uid","cn","givenName","sn"));
+ $tpl_base = preg_replace("/^[^,]+,".preg_quote(get_people_ou(), '/i')."/", '', $tpl_dn);
+ $this->usertab->by_object['user']->base= $tpl_base;
+ }
+
+ // Setting user Password
+ if((isset($dat['userPassword']))&&(!empty($dat['userPassword']))){
+ $password = $dat['userPassword'];
+ }else{
+ $rand_str="";
+ $feed = "0123456789abcdefghijklmnopqrstuvwxyz";
+ for ($e=0; $e < 8; $e++)
+ {
+ $rand_str .= substr($feed, rand(0, strlen($feed)-1), 1);
}
+ $password = $rand_str;
+ }
- /* Insert in the LDAP tree */
- if(count($this->usertab->check())) {
- msg_dialog::displayChecks($this->usertab->check());
- $this->csvinfo['sorteddata'][$i]['status']="<b>"._("failed")."</b>";
- $failing = $i+1;
- break;
- } else {
- $this->csvinfo['sorteddata'][$i]['status']=_("ok");
- $this->usertab->save();
- change_password($this->usertab->dn,$password);
- }
+ /* Insert in the LDAP tree */
+ if(count($this->usertab->check())) {
+ msg_dialog::displayChecks($this->usertab->check());
+ $this->csvinfo['sorteddata'][$i]['status']="<b>"._("failed")."</b>";
+ $failing = $i+1;
+ break;
+ } else {
+ $this->csvinfo['sorteddata'][$i]['status']=_("ok");
+ $this->usertab->save();
+ change_password($this->usertab->dn,$password);
}
}
if($this->csvinfo['shownrowscount']> $this->csvinfo['rows'])$this->csvinfo['shownrowscount']=$this->csvinfo['rows'];
$dataouts = array();
- for($i =$begin; $i <= $end; $i++) {
+ for($i =$begin; ($i <= $end) && (isset($this->csvinfo['sorteddata'][($i)])); $i++) {
if(is_array($this->csvinfo['sorteddata'][($i)])){
foreach($this->csvinfo['sorteddata'][($i)] as $dat){
$dataouts[]=$dat;
diff --git a/gosa-plugins/ldapmanager/addons/ldapmanager/contentcsv.tpl b/gosa-plugins/ldapmanager/addons/ldapmanager/contentcsv.tpl
index b89ba7ca34e1942ab5895cb592fbb6735c94258d..5ee7c7aab86d65d644a673c2ef02e347865b5cda 100644 (file)
<p>
- {t}The CSV import plugin provides methods to generate user accounts from a file containing Comma Seperated Values. The administrator can decide which columns should be transfered to which attribute. Note that you must have at least the UID, GIVENNAME and SURNAME set.{/t}
+ {t}The CSV import plugin provides methods to generate user accounts from a file containing Comma Seperated Values. The administrator can decide which columns should be transfered to which attribute. Note that you must have at least the GIVENNAME and SURNAME set.{/t}
</p>
<p class="seperator"> </p>