function ruleInputsInfer($s3ql, $db, $user_id) { $s3ql['where']['subject'] = $s3ql['where']['subject'] != '' ? $s3ql['where']['subject'] : ($s3ql['where']['subject_id'] != '' ? subject4subjectID(array('key' => $s3ql['key'], 'subject_id' => $s3ql['where']['subject_id'], 'db' => $db)) : ''); if ($s3ql['where']['verb_id'] == '') { #turn a literal verb into an instance of a class #class exists in project? no? create it;else find it's $VerbClass = projectVerbClass(array('project_id' => $s3ql['where']['project_id'], 'db' => $db, 'user_id' => $user_id)); if (!$VerbClass) { $to_create = array('project_id' => $s3ql['where']['project_id'], 'entity' => 's3dbVerb', 'notes' => 'Collection created by S3DB for holding Verbs'); $inputs = gatherInputs(array('element' => 'collection', 'to_create' => $to_create, 'db' => $db, 'user_id' => $user_id)); $inserted = insert_s3db(array('element' => 'collection', 'inputs' => $inputs, 'user_id' => $user_id, 'db' => $db)); #try again; $VerbClass = projectVerbClass(array('project_id' => $s3ql['where']['project_id'], 'db' => $db, 'user_id' => $user_id)); } #now create the instanceVerb $inputs = array('resource_class_id' => $VerbClass['resource_id'], 'project_id' => $s3ql['where']['project_id'], 'notes' => $s3ql['where']['verb'], 'created_by' => $user_id, 'entity' => $VerbClass['entity'], 'status' => 'A'); #echo '<pre>';print_r($inputs);exit; $inserted = insert_s3db(array('element' => 'item', 'inputs' => $inputs, 'user_id' => $user_id, 'db' => $db)); #echo '<pre>';print_r($inserted);exit; $s3ql['where']['verb_id'] = $inserted['item_id']; #echo '<pre>';print_r($s3ql);exit; } $s3ql['where']['verb'] = verb4instanceID(array('key' => $s3ql['key'], 'instance_id' => $s3ql['where']['verb_id'], 'db' => $db)); $s3ql['where']['object'] = $s3ql['where']['object'] != '' ? $s3ql['where']['object'] : ($s3ql['where']['object_id'] != '' ? object4objectID(array('key' => $s3ql['key'], 'object_id' => $s3ql['where']['object_id'], 'db' => $db)) : $s3ql['where']['object_id']); #echo '<pre>';print_r($s3ql);exit; return $s3ql; }
function bindRemoteUser($I) { global $timer; ##$bound = bindRemoteUser(compact('remote_user_id', 'user_id', 'db','user_info')) ###Create a binding account for remote users; although this is not mandatory for authentication, it maintains consistency within the deployment, and giving parent user (user_id) power to change the default permission level extract($I); $element = 'user'; ##Does this remote user exist already locally? This may have been checked before; remove this part if that is true $local_info = s3info($element, $remote_user_id, $db); if ($timer) { $timer->setMarker('Binding remote user'); } if (!$local_info) { $password = random_string(15); foreach ($GLOBALS['dbstruct']['users'] as $inp_name) { $to_create[$inp_name] = $remote_user_info[$inp_name]; } ##Replace here to create with data that need to be local for this deployment $to_create['account_lid'] = $to_create['account_lid'] . '@D' . ereg_replace('^D', '', $GLOBALS['Did']); ##Account login must be different $to_create['account_type'] = 'r'; $to_create['account_group'] = 'r'; $to_create['created_by'] = $user_id; $to_create['password'] = $password; ##Temporarily create an account email for this user; to email will be sent but user email does need to be updated upon first login $to_create['account_email'] = $remote_user_id . '@D' . ereg_replace('^D', '', $GLOBALS['Did']); $inputs = gatherInputs(compact('element', 'user_id', 'db', 'format', 'to_create')); $inputs['account_id'] = $remote_user_id; list($valid, $message, $id) = insert_s3db(compact('element', 'inputs', 'user_id', 'db')); ##Send the user's owner an email with the password for the new user include_once S3DB_SERVER_ROOT . '/s3dbcore/s3email.php'; ##Small fix for google emails, as authority = google email does get the '.com' portion $user_email = ereg_replace('@gmail$', '@gmail.com', $user_email); $message .= sprintf("%s\n\n", 'Dear ' . $username); $message .= sprintf("%s\n", "You have created an account for remote user " . $remote_user_id . " in S3DB deployment " . S3DB_URI_BASE); $message .= sprintf("%s\n", $inputs['account_uname'] . " can now login at " . S3DB_URI_BASE . 'login.php'); $message .= sprintf("%s\n", "Login: "******"%\n\n", 'Password: '******'The S3DB team.(http://www.s3db.org)'); $message .= sprintf("%s\n\n", 'Note: Please do not reply to this email, this is an automated message'); #send_email(array('email'=>array($user_email), 'subject'=>'Account for remote user created', 'message'=>$message)); if ($valid) { return true; } else { return false; } } else { return true; } }