function tryInsertUser(DatabaseBase $db, GWTUser $u) { $res = $db->select("webmaster_user_accounts", array('user_id'), array("user_name" => $u->getEmail()), __METHOD__); $obj = null; if ($obj = $res->fetchObject()) { return $obj->user_id; } //echo "insert: " . $u->getEmail() . "\n"; $user_id = generateUserId($db); if ($db->insert("webmaster_user_accounts", array("user_id" => $user_id, "user_name" => $u->getEmail(), "user_password" => $u->getPassword()))) { throw new Exception("can't insert user id = " . $user_id . " name = " . $u->getEmail()); } return $user_id; }
$cafe_details = new CafeDetails(); $sugar_soap = new SugarSoap(); //getting values from post $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $department = $_POST['department']; $role_id = $_POST['role']; $counttry = $_POST['country']; $state = $_POST['state']; $city = $_POST['city']; $reports_to_id = $_SESSION['user_id']; $name = $first_name . ' ' . $last_name; if ($session_id) { if ($cafedb_result = $cafe_details->insertEmp($name, $city)) { $id = $cafe_details->getMaxEmployeeId(); $user_id = generateUserId($city, $id); //calling function to enter values in sugar crm, using soap $sugar_result = $sugar_soap->insertEmployee($session_id, $user_id, $first_name, $last_name, $department, $country, $state, $city, $phone_mobile, $reports_to_id); } else { echo 'can not insert in database'; } } else { header("Location: ../account/login.php"); } //redirecting to the confirmation page if ($sugar_result) { $emp_id = $cafe_mgmt->getEmpId($user_id); $em_ass = $cafe_mgmt->assgnRole($emp_id, $role_id); $em_result = $cafe_mgmt->updateAssignEmUser($emp_id, $role_id, $city); if ($em_result && $em_ass) { header("Location: crt_emp_conf.php");