} $action = "create"; // Go back to create page } } } // Action ajout groupe utilisateur if (($action == 'addgroup' || $action == 'removegroup') && $caneditfield) { if ($group) { $editgroup = new UserGroup($db); $editgroup->fetch($group); $editgroup->oldcopy = dol_clone($editgroup); $edituser = new User($db); $edituser->fetch($id); if ($action == 'addgroup') { $edituser->SetInGroup($group, GETPOST('entity')); } if ($action == 'removegroup') { $edituser->RemoveFromGroup($group, GETPOST('entity')); } if ($result > 0) { header("Location: fiche.php?id=" . $id); exit; } else { $message .= $edituser->error; } } } if ($action == 'update' && !$_POST["cancel"]) { require_once DOL_DOCUMENT_ROOT . "/lib/files.lib.php"; if ($caneditfield) {
} } else { $langs->load("errors"); setEventMessages($langs->trans('ErrorForbidden'), null, 'errors'); } } // Add/Remove user into group if ($action == 'adduser' || $action == 'removeuser') { if ($caneditperms) { if ($userid) { $object->fetch($id); $object->oldcopy = clone $object; $edituser = new User($db); $edituser->fetch($userid); if ($action == 'adduser') { $result = $edituser->SetInGroup($object->id, !empty($conf->multicompany->transverse_mode) ? GETPOST('entity', 'int') : $object->entity); } if ($action == 'removeuser') { $result = $edituser->RemoveFromGroup($object->id, !empty($conf->multicompany->transverse_mode) ? GETPOST('entity', 'int') : $object->entity); } if ($result > 0) { header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $object->id); exit; } else { setEventMessages($edituser->error, $edituser->errors, 'errors'); } } } else { $langs->load("errors"); setEventMessages($langs->trans('ErrorForbidden'), null, 'errors'); }
} } // Action ajout groupe utilisateur if (($action == 'addgroup' || $action == 'removegroup') && $caneditfield) { if ($group) { $editgroup = new UserGroup($db); $editgroup->fetch($group); $editgroup->oldcopy=dol_clone($editgroup); $edituser = new User($db); $edituser->fetch($_GET["id"]); if ($action == 'addgroup') $edituser->SetInGroup($group,GETPOST('entity')); if ($action == 'removegroup') $edituser->RemoveFromGroup($group,GETPOST('entity')); if ($result > 0) { header("Location: fiche.php?id=".$_GET["id"]); exit; } else { $message.=$edituser->error; } } } if ($action == 'update' && ! $_POST["cancel"])
$fuser->fetch('', '', $userKey[0]); // Chargement du user concerné par le SID } else { if ($conf->global->LDAP_KEY_USERS == $conf->global->LDAP_FIELD_LOGIN) { $fuser->fetch('', $userKey[0]); // Chargement du user concerné par le login } } $userList[$userdn] = $fuser; } else { $fuser =& $userList[$userdn]; } $userIdList[$userdn] = $fuser->id; // Ajout de l'utilisateur dans le groupe if (!in_array($fuser->id, array_keys($group->members))) { $fuser->SetInGroup($group->id, $group->entity); echo $fuser->login . ' added' . "\n"; } } // 2 - Suppression des utilisateurs du groupe Dolibarr qui ne sont plus dans le groupe LDAP foreach ($group->members as $guser) { if (!in_array($guser->id, $userIdList)) { $guser->RemoveFromGroup($group->id, $group->entity); echo $guser->login . ' removed' . "\n"; } } } if (!$error || $forcecommit) { if (!$error) { print $langs->transnoentities("NoErrorCommitIsDone") . "\n"; } else {
/** * Create an external user with thirdparty and contact * * @param array $authentication Array of authentication information * @param array $thirdpartywithuser Datas * @return mixed */ function createUserFromThirdparty($authentication, $thirdpartywithuser) { global $db, $conf, $langs; dol_syslog("Function: createUserFromThirdparty login="******" id=" . $id . " ref=" . $ref . " ref_ext=" . $ref_ext); if ($authentication['entity']) { $conf->entity = $authentication['entity']; } $objectresp = array(); $errorcode = ''; $errorlabel = ''; $error = 0; $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel); if ($fuser->societe_id) { $socid = $fuser->societe_id; } if (!$error && !$thirdpartywithuser) { $error++; $errorcode = 'BAD_PARAMETERS'; $errorlabel = "Parameter thirdparty must be provided."; } if (!$error) { $fuser->getrights(); if ($fuser->rights->societe->creer) { $thirdparty = new Societe($db); // If a contact / company already exists with the email, return the corresponding socid $sql = "SELECT s.rowid as societe_id FROM " . MAIN_DB_PREFIX . "societe as s"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "socpeople as sp ON sp.fk_soc = s.rowid"; $sql .= " WHERE s.entity=" . $conf->entity; $sql .= " AND s.email='" . $db->escape($thirdpartywithuser['email']) . "'"; $sql .= " OR sp.email='" . $db->escape($thirdpartywithuser['email']) . "'"; $sql .= $db->plimit(1); $resql = $db->query($sql); if ($resql) { // If a company or contact is found with the same email we return an error $row = $db->fetch_object($resql); if ($row) { $error++; $errorcode = 'ALREADY_EXIST'; $errorlabel = 'Object not create : company or contact exists ' . $thirdpartywithuser['email']; } else { $db->begin(); /* * Company creation */ $thirdparty->name = $thirdpartywithuser['name_thirdparty']; $thirdparty->ref_ext = $thirdpartywithuser['ref_ext']; $thirdparty->address = $thirdpartywithuser['address']; $thirdparty->zip = $thirdpartywithuser['zip']; $thirdparty->town = $thirdpartywithuser['town']; $thirdparty->country_id = $thirdpartywithuser['country_id']; $thirdparty->country_code = $thirdpartywithuser['country_code']; // find the country id by code $langs->load("dict"); $sql = "SELECT rowid"; $sql .= " FROM " . MAIN_DB_PREFIX . "c_pays"; $sql .= " WHERE active = 1"; $sql .= " AND code='" . $thirdparty->country_code . "'"; $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); if ($num) { $obj = $db->fetch_object($resql); $thirdparty->country_id = $obj->rowid; } } $thirdparty->phone = $thirdpartywithuser['phone']; $thirdparty->fax = $thirdpartywithuser['fax']; $thirdparty->email = $thirdpartywithuser['email']; $thirdparty->url = $thirdpartywithuser['url']; $thirdparty->ape = $thirdpartywithuser['ape']; $thirdparty->idprof1 = $thirdpartywithuser['prof1']; $thirdparty->idprof2 = $thirdpartywithuser['prof2']; $thirdparty->idprof3 = $thirdpartywithuser['prof3']; $thirdparty->idprof4 = $thirdpartywithuser['prof4']; $thirdparty->idprof5 = $thirdpartywithuser['prof5']; $thirdparty->idprof6 = $thirdpartywithuser['prof6']; $thirdparty->client = $thirdpartywithuser['client']; $thirdparty->fournisseur = $thirdpartywithuser['fournisseur']; $socid_return = $thirdparty->create($fuser); if ($socid_return > 0) { $thirdparty->fetch($socid_return); /* * Contact creation * */ $contact = new Contact($db); $contact->socid = $thirdparty->id; $contact->lastname = $thirdpartywithuser['name']; $contact->firstname = $thirdpartywithuser['firstname']; $contact->civility_id = $thirdparty->civility_id; $contact->address = $thirdparty->address; $contact->zip = $thirdparty->zip; $contact->town = $thirdparty->town; $contact->email = $thirdparty->email; $contact->phone_pro = $thirdparty->phone; $contact->phone_mobile = $thirdpartywithuser['phone_mobile']; $contact->fax = $thirdparty->fax; $contact->statut = 1; $contact->country_id = $thirdparty->country_id; $contact->country_code = $thirdparty->country_code; //Retreive all extrafield for thirdsparty // fetch optionals attributes and labels $extrafields = new ExtraFields($db); $extralabels = $extrafields->fetch_name_optionals_label('socpeople', true); foreach ($extrafields->attribute_label as $key => $label) { $key = 'contact_options_' . $key; $key = substr($key, 8); // Remove 'contact_' prefix $contact->array_options[$key] = $thirdpartywithuser[$key]; } $contact_id = $contact->create($fuser); if ($contact_id > 0) { /* * User creation * */ $edituser = new User($db); $id = $edituser->create_from_contact($contact, $thirdpartywithuser["login"]); if ($id > 0) { $edituser->setPassword($fuser, trim($thirdpartywithuser['password'])); if ($thirdpartywithuser['group_id'] > 0) { $edituser->SetInGroup($thirdpartywithuser['group_id'], $conf->entity); } } else { $error++; $errorcode = 'NOT_CREATE'; $errorlabel = 'Object not create : ' . $edituser->error; } } else { $error++; $errorcode = 'NOT_CREATE'; $errorlabel = 'Object not create : ' . $contact->error; } if (!$error) { $db->commit(); $objectresp = array('result' => array('result_code' => 'OK', 'result_label' => 'SUCCESS'), 'id' => $socid_return); $error = 0; } } else { $error++; $errors = $thirdparty->error ? array($thirdparty->error) : $thirdparty->errors; } } } else { // retour creation KO $error++; $errorcode = 'NOT_CREATE'; $errorlabel = 'Object not create'; } } else { $error++; $errorcode = 'PERMISSION_DENIED'; $errorlabel = 'User does not have permission for this request'; } } if ($error) { $db->rollback(); $objectresp = array('result' => array('result_code' => $errorcode, 'result_label' => $errorlabel)); } return $objectresp; }
} } // Add/Remove user into group if ($action == 'adduser' || $action =='removeuser') { if ($caneditperms) { if ($userid) { $object->fetch($_GET["id"]); $object->oldcopy=dol_clone($object); $edituser = new User($db); $edituser->fetch($userid); if ($action == 'adduser') $result=$edituser->SetInGroup($object->id,GETPOST('entity')); if ($action == 'removeuser') $result=$edituser->RemoveFromGroup($object->id,GETPOST('entity')); if ($result > 0) { header("Location: fiche.php?id=".$object->id); exit; } else { $message.=$edituser->error; } } } else {