本文整理汇总了PHP中S3QLaction函数的典型用法代码示例。如果您正苦于以下问题:PHP S3QLaction函数的具体用法?PHP S3QLaction怎么用?PHP S3QLaction使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了S3QLaction函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render_statements
function render_statements($I)
{
$action = $GLOBALS['action'];
#all the possible links were separated ina script that gets always included
extract($I);
$_SESSION['current_color'] = '0';
$_SESSION['previous_verb'] = '';
#display all the rules in this class where the user has permission
$s3ql = compact('user_id', 'db');
$s3ql['select'] = '*';
$s3ql['from'] = 'statements';
$s3ql['where']['instance_id'] = $instance_info['instance_id'];
$statements = S3QLaction($s3ql);
#echo '<pre>';print_r($statements);exit;
#divide them by rules
if (is_array($statements)) {
foreach ($statements as $stat_info) {
$stats_per_rule[$stat_info['rule_id']][$stat_info['statement_id']] = $stat_info;
}
if (is_array($rules)) {
$rule_ids = array_map('grab_rule_id', $rules);
$tRules = array_combine($rule_ids, $rules);
}
#echo '<pre>';print_r($stats_per_rule);exit;
if (is_array($stats_per_rule) && is_array($tRules)) {
$stats = '';
$index = 1;
foreach ($stats_per_rule as $rule_id => $exist_stats) {
if ($tRules[$rule_id]['object'] != 'UID' && $tRules[$rule_id]['verb'] != 'has UID') {
$subject = $tRules[$rule_id]['subject'];
$verb = $tRules[$rule_id]['verb'];
$object = $tRules[$rule_id]['object'];
$rule_id = $tRules[$rule_id]['rule_id'];
#$rule_notes = preg_replace('/\(.*\)/', '', $rules[$i]['notes']);
$rule_notes = $tRules[$rule_id]['notes'];
$stats .= sprintf("\n%s\n", '<table width="100%" border="0"><tr bgcolor="lightyellow"><td colspan="2">');
$stats .= sprintf("%s\n", $index++ . '. ' . printVerbinColor($verb) . ' | <font size=4><b>' . $object . '</b></font> (R' . $rule_id . ') </td></tr><tr><td> <font size-=2>' . $rule_notes . '</font></td><td align="right">');
if ($tRules[$rule_id]['add_data']) {
$stats .= sprintf("%s\n", '<input type="button" value="Add" onClick="window.open(\'' . $action['insertstatement'] . '&rule_id=' . $rule_id . '\', \'_blank\', \'width=600, height=500, location=no, titlebar=no, scrollbars=yes, resizable=yes\')">');
}
$stats .= sprintf("%s\n", ' </td></tr>');
$stat = '';
$stat .= sprintf("%s\n", ' <tr><td colspan="2" style="color: navy; font-size: normal">');
if (is_array($exist_stats)) {
$stat .= render_substatements_without_grid($exist_stats, $db);
}
//$stat .= render_substatements($exist_stats, 'value', 'DESC');
$stat .= sprintf("%s\n", ' </td></tr>');
$stats .= $stat;
$stats .= sprintf("%s\n", ' <tr><td colspan="2"><br>');
$stats .= sprintf("%s\n", ' </td></tr>');
$stats .= sprintf("%s\n", '</table>');
}
}
}
}
return $stats;
}
示例2: create_resource
function create_resource($R)
{
extract($R);
if ($resource_info['iid'] == '') {
$resource_info['iid'] = '1';
}
$R['resource_info']['resource_id'] = find_latest_UID('resource', $db) + 1;
$resource_id_created = insert_resource($R);
if ($resource_id_created) {
$resource_id = find_latest_UID('resource', $db);
$resource_info['resource_id'] = $resource_id;
if ($resource_info['iid'] == '0') {
#INSERT LINE ON RULES TABLE
$rule_info = array('project_id' => $resource_info['project_id'], 'owner' => $user_id, 'subject' => $resource_info['entity'], 'subject_id' => $resource_info['resource_id'], 'verb' => 'has UID', 'object' => 'UID', 'notes' => nl2br($resource_info['notes']));
$db->query($sql, __LINE__, __FILE__);
$R['rule_info'] = $rule_info;
$rule_inserted = insert_rule($R);
if ($rule_inserted) {
$rule_info['rule_id'] = find_latest_UID('rule', $db);
$inputs = array('newsubject' => $resource_info['entity'], 'newverb' => 'has UID', 'newobject' => 'UID', 'newnotes' => nl2br($resource_info['notes']));
$action = 'create';
$log = compact('action', 'rule_info', 'user_id', 'project_id', 'db', 'inputs');
insert_rule_log($log);
}
#now check if there is any rule in the same project that already has this class as object.
$s3ql = compact('user_id', 'db');
$s3ql['from'] = 'rules';
$s3ql['where']['object'] = $resource_info['entity'];
$s3ql['where']['project_id'] = $resource_info['project_id'];
$object_rules = S3QLaction($s3ql);
if (is_array($object_rules)) {
foreach ($object_rules as $key => $rule_to_change) {
$s3ql = compact('user_id', 'db');
$s3ql['edit'] = 'rule';
$s3ql['where']['rule_id'] = $rule_to_change['rule_id'];
$s3ql['set']['object_id'] = $resource_id;
$done = S3QLaction($s3ql);
}
}
} else {
$statement_info = array('project_id' => $resource_info['project_id'], 'resource_id' => $resource_id, 'rule_id' => get_rule_id_by_entity_id($resource_info['resource_class_id'], $resource_info['project_id'], $db), 'value' => $resource_id, 'notes' => $resource_info['notes'], 'created_by' => $resource_info['owner'], 'db' => $db);
$R['statement_info'] = $statement_info;
insert_statement($R);
}
return $resource_id;
}
}
示例3: urldecode
#echo '<pre>';print_r($rule);
if (urldecode($rule['OBJECT']) != 'UID') {
$s3ql['insert'] = 'rule';
$s3ql['where'] = '';
$s3ql['where']['project_id'] = $project_id;
$s3ql['where']['subject_id'] = $class_id;
$s3ql['where']['verb'] = urldecode($rule['VERB']);
if ($classes[urldecode($rule['OBJECT'])] != '') {
#was there a class created with this object name?
$s3ql['where']['object_id'] = $classes[$rule['OBJECT']]['class_id'];
} else {
$s3ql['where']['object'] = urldecode($rule['OBJECT']);
}
$s3ql['where']['notes'] = urldecode($rule['NOTES']);
$s3ql['format'] = 'html';
$ruleInserted = S3QLaction($s3ql);
$msg = html2cell($ruleInserted);
$msg = $msg[2];
#echo $ruleInserted;
#ereg('<error>([0-9]+)</error>(.*)<(rule_id|message)>(.*)</(rule_id|message)>', $ruleInserted, $s3qloutRule);
if ($msg['error_code'] == '0') {
$rule_id = $msg['rule_id'];
$report .= '<tr><td><font color = "#00CC33">Rule ' . $rule['SUBJECT'] . ' ' . $rule['VERB'] . ' ' . $rule['OBJECT'] . ' created</font></td></tr>';
} else {
echo urldecode($rule['OBJECT']) != 'UID';
#echo '<pre>';print_r($rule);
$report .= '<tr><td><font color = "red">Rule ' . $rule['SUBJECT'] . ' ' . $rule['VERB'] . ' ' . $rule['OBJECT'] . ' was NOT created. Reason: ' . $msg['message'] . '</font></td></tr>';
}
}
}
}
示例4: formatReturn
include_once S3DB_SERVER_ROOT . '/s3dbcore/common_functions.inc.php';
$format = $_REQUEST['format'];
if ($format == '') {
$format = 'html';
}
#if a key has been provided, validate the key
$key = $_REQUEST['key'];
include_once 'core.header.php';
#echo '<pre>';print_r($db);
$query = $_REQUEST['query'] != "" ? $_REQUEST['query'] : $_REQUEST['q'];
if ($query == '') {
echo formatReturn('3', 'Please input an S3QL query.', $format, '');
exit;
}
$q = compact('query', 'format', 'key', 'user_id', 'db');
$s3ql = parse_xml_query($q);
$s3ql['db'] = $db;
$s3ql['user_id'] = $user_id;
$data = S3QLaction($s3ql);
#echo '<pre>';print_r($data);
if (count($data) > 1) {
$s3ql['order_by'] = 'created_on desc';
$s3ql['limit'] = '1';
$data = S3QLaction($s3ql);
}
if ($data[0]['file_name'] == '') {
echo $data[0]['value'];
} else {
$statement_info = $data[0];
pushDownload2Header(compact('statement_info', 'db', 'user_id', 'format'));
}
示例5: compact
$account_status = 'Active';
$account_type = 'User';
$checked = 'checked';
$loginid_required = '*';
$uname_required = '*';
$password_required = '*';
$password2_required = '*';
$default_message = '* required';
$email_warn = '*';
#list all the groups where this user can make changes
$s3ql = compact('user_id', 'db');
$s3ql['select'] = '*';
$s3ql['from'] = 'groups';
#$s3ql['where']['user_id']=$user_id;
#echo '<pre>';print_r($s3ql);
$groups = S3QLaction($s3ql);
#echo '<pre>';print_r($groups);
#make a select list
// if ($user_id=='1') {
// $group_select_list .= '<option value="1">Admin</option>';
// }
if (is_array($groups)) {
foreach ($groups as $group_info) {
if ($group_info['account_id'] == '3') {
$selected = " selected";
} else {
$selected = "";
}
$group_select_list .= '<option value="' . $group_info['account_id'] . '" ' . $selected . '>' . $group_info['account_lid'] . '</option>';
}
}
示例6: compact
if ($_POST['deleteuser']) {
#and make the user inactive
$s3ql = compact('user_id', 'db');
if ($_POST['deleteuser'] == 'Remove from Deployment') {
$s3ql['delete'] = 'user';
$s3ql['where']['user_id'] = $imp_user_id;
$s3ql['flag'] = 'resource';
} elseif ($_POST['deleteuser'] == 'Deactivate Account') {
$s3ql['update'] = 'user';
$s3ql['where']['user_id'] = $imp_user_id;
$s3ql['where']['account_status'] = 'I';
#$s3ql['where']['permission_level']='000';
}
$s3ql['format'] = 'html';
#echo '<pre>';print_r($s3ql);exit;
$deleted = S3QLaction($s3ql);
$deleted = html2cell($deleted);
#echo $deleted;
#exit;
if ($deleted[2]['error_code'] == '0') {
Header('Location: ' . $action['listusers']);
exit;
} else {
ereg('<message>(.*)</message>', $deleted, $s3qlouput);
$message = $s3qlouput[0];
}
}
include '../S3DBjavascript.php';
include '../tabs.php';
#echo '<pre>';print_r($users);exit;
#$user_list=create_user_list($users);
示例7: find_final_acl
$sortorder = $_REQUEST['orderBy'];
$direction = $_REQUEST['direction'];
$project_id = $_REQUEST['project_id'];
#$acl = find_final_acl($user_id, $project_id, $db);
$uni = compact('db', 'acl', 'user_id', 'key', 'project_id', 'dbstruct');
#relevant extra arguments
$args = '?key=' . $_REQUEST['key'];
include '../webActions.php';
#include the specification of the link map. Must be put in here becuase arguments vary.
#Find all the projects for this user
$s3ql = compact('user_id', 'db');
$s3ql['from'] = 'projects';
if ($sortorder != '') {
$s3ql['order_by'] = $sortorder . ' ' . $direction;
}
$projects = S3QLaction($s3ql);
$_SESSION[$user_id]['projects'] = $projects;
#this is the directory where upload of xml or n3 will go before i start using it for building projects
#$totaldirname = S3DB_SERVER_ROOT.$GLOBALS['s3db_info']['server']['db']['uploads_file'].'/schemas';
$totaldirname = $GLOBALS['s3db_info']['server']['db']['uploads_folder'] . $GLOBALS['s3db_info']['server']['db']['uploads_file'] . '/tmps3db';
if ($_POST['submitschema']) {
if (!file_exists($totaldirname)) {
mkdir($totaldirname, 0777);
}
$indexfile = $totaldirname . '/index.php';
if (file_exists($totaldirname)) {
file_put_contents($indexfile, 'This folder cannot be accessed');
}
$uploadfile = $totaldirname . '/xmlschema.s3db';
list($filename, $extension) = explode(".", $_FILES['schema']['name']);
#read the first 100 lines or so and chech if it is XML
示例8: create_nodes
function create_nodes($O)
{
$action = $GLOBALS['action'];
extract($O);
$project_info = s3info('project', $project_id, $db);
$project_node .= sprintf("\t\t%s\n", '<NODE nodeID="P' . $project_info['project_id'] . '">');
$project_node .= sprintf("\t\t\t%s\n", '<NODE_LOCATION x="0" y="0" visible="true"/>');
$project_node .= sprintf("\t\t\t%s\n", '<NODE_HINT hint="' . str_replace("\"", "", htmlentities($project_info['project_description'])) . '" width="300" height="-1" isHTML="false"/>');
$project_node .= sprintf("\t\t\t%s\n", '<NODE_LABEL label="' . $project_info['project_name'] . '" shape="3" backColor="0000FF" textColor="FFFF00" fontSize="12"/>');
$project_node .= sprintf("\t\t\t%s\n", '<NODE_URL url="' . htmlentities($action['project']) . '" urlIsLocal="true" urlIsXML="false"/>');
#$project_node.= sprintf("\t\t\t%s\n",'<NODE_URL url="../project/project.php?project_id='.$_REQUEST['project_id'].'" urlIsLocal="true" urlIsXML="false"/>');
$project_node .= sprintf("\t\t%s\n", '</NODE>');
$s3ql['db'] = $db;
$s3ql['user_id'] = $user_id;
$s3ql['select'] = '*';
$s3ql['from'] = 'rules';
$s3ql['where']['project_id'] = $_REQUEST['project_id'];
$s3ql['where']['object'] = "!=UID";
#$rules = s3list($s3ql);
$rules = S3QLaction($s3ql);
$GLOBALS['rules'] = $rules;
#Create the node for the regular resources
#List all classes in project
$s3ql = compact('user_id', 'db');
$s3ql['select'] = '*';
$s3ql['from'] = 'classes';
$s3ql['where']['project_id'] = $_REQUEST['project_id'];
#$resources = s3list($s3ql);
$resources = S3QLaction($s3ql);
$GLOBALS['collections'] = $resources;
if (is_array($resources)) {
$C = grab_id('collection', $resources);
#=>these are the ids of all allowed nodes
foreach ($resources as $resource_info) {
//Lena -created this session because map doesn't allow more than 1 get, but for queryresource to run properly we need at least 2 get's
$rule_id = get_rule_id_by_entity_id($resource_info['resource_id'], $resource_info['project_id'], $db);
$subject = str_replace($toReplace, $replace, htmlentities($resource_info['entity']));
$notes = str_replace($toReplace, $replace, htmlentities($resource_info['notes']));
if ($resource_info['project_id'] == $_REQUEST['project_id']) {
$color = 'FF0000';
} else {
$color = 'FF6600';
}
$resource_id = $resource_info['resource_id'];
$subject_node .= sprintf("\t\t%s\n", '<NODE nodeID="C' . $resource_id . '">');
$subject_node .= sprintf("\t\t\t%s\n", '<NODE_LOCATION x="0" y="0" visible="false"/>');
$subject_node .= sprintf("\t\t\t%s\n", '<NODE_HINT hint="' . $notes . '" width="300" height="-1" isHTML="true"/>');
$subject_node .= sprintf("\t\t\t%s\n", '<NODE_LABEL label="' . $subject . '" shape="2" backColor="' . $color . '" textColor="FFFFFF" fontSize="14"/>');
$subject_node .= sprintf("\t\t\t%s\n", '<NODE_URL url="' . htmlentities($action['resource']) . '&class_id=' . $resource_info['resource_id'] . '" urlIsLocal="true" urlIsXML="false"/>');
$subject_node .= sprintf("\t\t%s\n", '</NODE>');
}
#and finally... the nodes for the objects...
if (is_array($rules)) {
#foreach($objects as $object)
foreach ($rules as $rule_info) {
$subject = str_replace($toReplace, $replace, htmlentities($rule_info['subject']));
$verb = str_replace($toReplace, $replace, htmlentities($rule_info['verb']));
$object = str_replace($toReplace, $replace, htmlentities($rule_info['object']));
$notes = str_replace($toReplace, $replace, htmlentities($rule_info['notes']));
#is the rule from this project? if not, print a different color
if ($rule_info['project_id'] == $_REQUEST['project_id']) {
$objcolor = '336600';
$classColor = 'FF0000';
} else {
$objcolor = '009900';
$classColor = 'FF6600';
}
if ($rule_info['object'] != 'UID' || $rule_info['verb'] != 'has UID') {
$object_node .= sprintf("\t\t%s\n", '<NODE nodeID="R' . $rule_info['rule_id'] . '">');
$object_node .= sprintf("\t\t\t%s\n", '<NODE_LOCATION x="0" y="0" visible="false"/>');
if ($rule_info['object_id'] == '') {
$object_node .= sprintf("\t\t\t%s\n", '<NODE_LABEL label="' . $object . '" shape="1" backColor="' . $objcolor . '" textColor="FFFF00" fontSize="12"/>');
$object_node .= sprintf("\t\t\t%s\n", '<NODE_URL url="' . htmlentities($action['rule']) . '&class_id=' . $rule_info['subject_id'] . '&rule_id=' . $rule_info['rule_id'] . '" urlIsLocal="true" urlIsXML="false"/>');
$object_node .= sprintf("\t\t\t%s\n", '<NODE_HINT hint="' . $notes . '" width="300" height="-1" isHTML="false"/>');
} elseif (in_array($rule_info['object_id'], $C)) {
##Collection must either exist already as a visible node or the map will crash
$object_node .= sprintf("\t\t\t%s\n", '<NODE_LABEL label="' . $object . '" shape="1" backColor="' . $classColor . '" textColor="FFFFFF" fontSize="12"/>');
$object_node .= sprintf("\t\t\t%s\n", '<NODE_URL url="' . htmlentities($action['resource']) . '&class_id=' . $rule_info['object_id'] . '" urlIsLocal="true" urlIsXML="false"/>');
$object_node .= sprintf("\t\t\t%s\n", '<NODE_HINT hint="' . $notes . '" width="300" height="-1" isHTML="false"/>');
} else {
$object_node .= sprintf("\t\t\t%s\n", '<NODE_LABEL label="' . $object . '" shape="1" backColor="#EFEFEF" textColor="FFFF00" fontSize="12"/>');
$object_node .= sprintf("\t\t\t%s\n", '<NODE_HINT hint="User is not allowed in this Collection" width="300" height="-1" isHTML="false"/>');
}
$object_node .= sprintf("\t\t%s\n", '</NODE>');
}
}
}
#find all projects involved in the rules of this project
#find out how many project_ids there are
if (is_array($rules)) {
$extraproject_ids = array_map('grab_project_id', $rules);
$extraproject_ids = array_diff(array_unique($extraproject_ids), array($_REQUEST['project_id']));
#echo '<pre>';print_r($extraproject_ids);
#Create extra projects nodes
if (is_array($extraproject_ids)) {
foreach ($extraproject_ids as $extra_project_id) {
$project_info = get_info('project', $extra_project_id, $db);
$extra_project_node .= sprintf("\t\t%s\n", '<NODE nodeID="P' . $extra_project_id . '">');
$extra_project_node .= sprintf("\t\t\t%s\n", '<NODE_LOCATION x="1" y="1" visible="true"/>');
$extra_project_node .= sprintf("\t\t\t%s\n", '<NODE_HINT hint="' . str_replace("\"", "", $project_info['project_description']) . '" width="300" height="-1" isHTML="false"/>');
//.........这里部分代码省略.........
示例9: compact
} else {
$s3ql = compact('db', 'user_id');
$s3ql['select'] = '*';
$s3ql['from'] = 'items';
$s3ql['where']['collection_id'] = $class_id;
#$s3ql['where']['project_id'] = $project_id;
$instances = S3QLaction($s3ql);
}
#echo '<pre>';print_r($instances);
#For finding all the rules that this resource involves, change S a little bit
$s3ql = compact('db', 'user_id');
$s3ql['select'] = '*';
$s3ql['from'] = 'rules';
$s3ql['where']['subject_id'] = $class_id;
$s3ql['where']['object'] = "!='UID'";
$rules = S3QLaction($s3ql);
#$rules = include_all_class_id(compact('rules', 'project_id', 'db'));
} else {
#Building the query
$ruleScope = array();
foreach ($inputs as $key => $value) {
$ruleScope[ereg_replace('^R', '', $key)] = stripslashes($value);
}
$q = array('rules' => array_keys($ruleScope), 'logical' => array_fill(0, count($inputs), 'and'), 'RuleValuePair' => $ruleScope, 'db' => $db);
$instances = query_statements($q);
}
##Find the values that are to be sent to datamatrix.php, both header and data
if (is_array($rules) && !empty($rules)) {
$verbs = array_map('grab_verb', $rules);
foreach ($verbs as $i => $value) {
$objects = array_map('grab_object', $rules, $verbs);
示例10: compact
# $create_key_line .= '<option value="'.$s3.'">'.$s3.'</option>';
#}
$create_key_line .= '</select></td>';
#$create_key_line .= '<td width="10%"><input type="text" name="ID"></td>';
$create_key_line .= '<td width="10%"><input type ="submit" name="Submit_key" value="New Key"></td></tr>';
include S3DB_SERVER_ROOT . '/s3style.php';
include S3DB_SERVER_ROOT . '/tabs.php';
#Find existing keys
$s3ql = compact('user_id', 'db');
$s3ql['select'] = '*';
$s3ql['from'] = 'keys';
if ($_REQUEST['orderBy'] != '') {
$s3ql['order_by'] = $_REQUEST['orderBy'] . ' ' . $_REQUEST['direction'];
}
#echo '<pre>';print_r($s3ql);
$user_keys = S3QLaction($s3ql);
#echo '<pre>';print_r($user_keys);exit;
#Create the table with exsiting keys
#Parse to the template
$add_key_form = $create_key_line;
if (is_array($user_keys) && !empty($user_keys)) {
$existing_keys_header = "<tr bgcolor='#80BBFF'><td colspan='9' align='center'>Existing Keys</td></b></tr><td><BR></td>";
$columns = array('Key', 'Requested By', 'Expires', 'Notes', 'Actions');
#echo '<pre>';print_r($user_keys);
$user_keys = replace_created_by($user_keys, $db);
$keys_table = render_elements($user_keys, $acl, $columns, 'access_keys');
}
?>
<table class="contents">
<table class="top" align="center">
<tr><td>
示例11: readWriteExtInput
function readWriteExtInput($element, $info, $s3ql_in)
{
extract($s3ql_in);
#$idReplacements=($GLOBALS['idReplacements']=='')?array():$GLOBALS['idReplacements'];
//if($info[$element.'_id']=="") { $info[$element.'_id'] = s3id(); }
#echo $element.$info[$element.'_id'].chr(13).chr(10).'<br />';
if ($info[$element . '_id'] != '' && $info['object'] != 'UID') {
$s3ql = $s3ql_in;
$s3ql['insert'] = $element;
if ($element == 'item' && $info['notes'] == '') {
##insert something for ntoes, otherwise, rdf import will not create a new item
$info['notes'] = " ";
}
#echo "Building s3ql query".chr(10);
foreach ($info as $info_key => $info_value) {
if (is_array($GLOBALS['idReplacements']) && in_array($info_value, array_keys($GLOBALS['idReplacements'])) && ereg('_id$|created_by', $info_key)) {
$info_value = $GLOBALS['idReplacements'][$info_value];
}
if (in_array($info_key, $GLOBALS['s3input'][$element]) && $info_key != 'password') {
#test for file
if ($element == 'statement' && $info_key == 'value') {
if (isS3DBfile($info_value) || isS3DBLink($info_value)) {
#write file to folder
#echo "Creating file ".$info_value.chr(10);
#echo $info_value;
$filekey = moveS3DBfile($info_value, $db, $user_id);
$s3ql['insert'] = 'file';
$info_key = 'filekey';
$info_value = $filekey;
$s3ql['where'][$info_key] = $info_value;
}
}
$s3ql['where'][$info_key] = urldecode($info_value);
}
}
#echo "Run the query for ".$element.' '.$info[$element.'_id'].chr(10);
$s3ql['format'] = 'php';
$inserted = S3QLaction($s3ql);
$msg = unserialize($inserted);
$inserted = $msg[0];
#$inserted = html2cell($inserted);$inserted=$inserted[2];
$newS3QL = $s3ql;
$try = 1;
#while(ereg('^9|4$',$inserted['error_code']) && $try<10) #this means this resource already existed.
while (!ereg('^0$', $inserted['error_code']) && $try < 10) {
$newS3QL['where'][$element . '_id']++;
$newS3QL['format'] = 'php';
$inserted = S3QLaction($newS3QL);
$msg = unserialize($inserted);
$inserted = $msg[0];
#$inserted = html2cell($inserted);$inserted=$inserted[2];
$try++;
}
#if(ereg('^9|4$',$inserted['error_code']))
if (!ereg('^0$', $inserted['error_code'])) {
$error_log .= "Could not create " . $newS3QL['insert'] . ". Gave up after 5 attempts. " . $inserted['message'] . '<br />';
}
if ($inserted['error_code'] != '0' && $inputs['su3d']) {
$eeee = @fopen('tmp/error_log_' . date('Ymd'), 'a+');
@fwrite($eeee, serialize(array('q' => $s3ql, 'new' => $newS3QL, 'ms' => $inserted['message'])));
echo "Here are the queries that were not valid:";
echo '<pre>';
print_r($s3ql);
echo '<pre>';
print_r($newS3QL);
echo '<pre>';
print_r($inserted);
}
// if($s3ql['insert']=='file')
// {
// echo '<pre>';print_r($s3ql);
// echo '<pre>';print_r($inserted);
// exit;
// }
##User that is inserting must have permission to further insert stuff in this id
if ($inserted['error_code'] == '0') {
switch ($element) {
case 'project':
$permission_info = array('uid' => 'P' . $inserted[$element . '_id'], 'shared_with' => 'U' . $user_id, 'permission_level' => '222');
case 'collection':
$permission_info = array('uid' => 'C' . $inserted[$element . '_id'], 'shared_with' => 'U' . $user_id, 'permission_level' => '222');
break;
case 'rule':
$permission_info = array('uid' => 'R' . $inserted[$element . '_id'], 'shared_with' => 'U' . $user_id, 'permission_level' => '222');
break;
case 'item':
$permission_info = array('uid' => 'I' . $inserted[$element . '_id'], 'shared_with' => 'U' . $user_id, 'permission_level' => '222');
case 'statement':
$permission_info = array('uid' => 'S' . $inserted[$element . '_id'], 'shared_with' => 'U' . $user_id, 'permission_level' => '222');
break;
}
$p = insert_permission(array('permission_info' => $permission_info, 'db' => $db, 'user_id' => "'-100'"));
}
if ($inserted[$element . '_id'] != '' && $inserted[$element . '_id'] != $s3ql['where'][$element . '_id']) {
##need to re-issue all the ids that rely on this one fro this moment forward
$GLOBALS['idReplacements'][$s3ql['where'][$element . '_id']] = $inserted[$element . '_id'];
#array_push($idReplacements, array($s3ql['where'][$element.'_id']=>$inserted[$element.'_id']));
}
#echo '<pre>';print_r($GLOBALS['idReplacements']);
#if($element=='statement' && $filekey!='')
//.........这里部分代码省略.........
示例12: S3QLaction
function S3QLaction($s3ql)
{
extract($s3ql);
#grab a few relevant varuales
$regexp = $GLOBALS['regexp'];
$dbstruct = $GLOBALS['dbstruct'];
#map a few vairables
$s3map = $GLOBALS['s3map'];
$format = $s3ql['format'];
#Error messages
extract($GLOBALS['messages']);
#database and user identification
if (!is_object($db)) {
$db = $_SESSION['db'];
}
$key = $_REQUEST['key'] ? $_REQUEST['key'] : $s3ql['key'];
$user_id = $user_id ? $user_id : $_SESSION['user']['account_id'];
$user_info = s3info('users', $user_id, $db);
if (!$user_id && !$db) {
if (!$key) {
return formatReturn($GLOBALS['error_codes']['no_permission_message'], 'Please specify user_id and db or a key', $format, '');
}
#re-chekc if user provided is the same for key provided
}
$s3ql = array_diff_key($s3ql, array('db' => '', 'user_id' => ''));
#take out from the array what needed to be included for wihitn S3DB queries
if ($s3ql['update'] != '') {
$s3ql['edit'] = $s3ql['update'];
#update is closer to SQL, although original was edit. Must keep edit to be backward compatible
$s3ql = array_filter(array_diff_key($s3ql, array('update' => 1)));
}
#identify the action
$possible_actions = array('insert', 'edit', 'delete', 'select', 'update', 'grant');
foreach ($possible_actions as $someaction) {
if ($s3ql[$someaction] != '') {
$action = $someaction;
}
}
#if there is nothing as action, assume a select
if ($action == '') {
$action = 'select';
}
#identify the target
if (ereg('(insert|edit|update|delete|grant)', $action)) {
$s3ql['from'] = $s3ql[$action] == '' ? $_REQUEST[$action] : $s3ql[$action];
} elseif (ereg('(select)', $action)) {
$s3ql['from'] = $s3ql['from'] == '' ? $_REQUEST['from'] : $s3ql['from'];
}
#if there is no target, assume projects
if ($s3ql['from'] == '') {
$s3ql['from'] = 'projects';
}
if ($s3ql['from'] == 'permission') {
$s3ql['from'] = 'user';
}
if ($s3ql['from'] == 'class') {
$s3ql['from'] = 'collection';
}
if ($s3ql['from'] == 'instance') {
$s3ql['from'] = 'item';
}
#these are targets ONLY for insert/edit/delete. Select takes plurals... was a bad idea, I know :-( but is much more intuitive :-)
$possible_targets = array('permission', 'user', 'group', 'key', 'project', 'collection', 'item', 'rule', 'statement', 'filekey');
#start taking action
switch ($action) {
case 'select':
$data = selectQuery(compact('s3ql', 'db', 'user_id', 'format'));
return $data;
break;
#Close select queries
#Close select queries
case 'insert':
#echo '<pre>';print_r($s3ql);exit;
#map s3ql input to s3db structure requirements
if ($s3ql['insert'] == 'class') {
$s3ql['insert'] = 'collection';
}
if ($s3ql['insert'] == 'instance') {
$s3ql['insert'] = 'item';
}
if ($s3ql['where']['notes'] != '') {
$s3ql['where']['notes'] = $s3ql['where']['notes'];
}
if ($s3ql['where']['value'] != '') {
$s3ql['where']['value'] = $s3ql['where']['value'];
}
##build inputs and oldvalues for validation and insert functions
$tranformed = S3QLselectTransform(compact('s3ql', 'db', 'user_id'));
$s3ql = $tranformed['s3ql'];
$element = $s3ql['insert'];
$element_id = $s3ql['where'][$element . '_id'];
$letter = strtoupper(substr($element, 0, 1));
$uid = $letter . $element_id;
$required = array('key' => array(), 'project' => array('project_name'), 'collection' => array('project_id', 'entity'), 'rule' => array('project_id', 'subject_id', 'verb', 'object'), 'item' => array('collection_id'), 'statement' => array('item_id', 'rule_id', 'value'), 'file' => array('item_id', 'rule_id', 'filekey'), 'user' => array('account_lid', 'account_email'), 'group' => array('account_lid'));
if (!in_array($element, array_keys($required))) {
return formatReturn($GLOBALS['error_codes']['wrong_input'], $element . ' is not a valid S3DB element. Valid elements: key, project, collection, rule, item, statement, file', $format, '');
}
#if a subject is provided instead of a subject id in rule, dont break because of that. Find the subject
#THIS PART NEEDS TO B HERE BECAUSE IT THE MANDATORY FIELDS ARE 'OR'
if ($element == 'rule') {
//.........这里部分代码省略.........
示例13: check_user_management2
function check_user_management2($C)
{
extract($C);
#Now let's check again if we have every necessary item
#Project
#$user_proj=array();
$s3ql = compact('user_id', 'db');
$s3ql['from'] = 'project';
$s3ql['where']['name'] = $project_name;
$s3ql['order_by'] = 'created_on desc';
$done = S3QLaction($s3ql);
if ($user_proj['project_id'] != "" && $user_proj['project_id'] != $done[0]['project_id']) {
$user_proj = array();
$user_proj['project_id'] = $done[0]['project_id'];
unlink($GLOBALS['uploads'] . 'user_proj');
$file_fill = 1;
#this means that the project in file is not in sync with the proj on s3db
} else {
$user_proj['project_id'] = $done[0]['project_id'];
}
if ($done[0]['project_id'] == "") {
$s3ql = compact('user_id', 'db');
$s3ql['insert'] = 'project';
$s3ql['where']['name'] = $project_name;
$s3ql['format'] = 'php';
$done = S3QLaction($s3ql);
$msg = unserialize($done);
$msg = $msg[0];
$user_proj['project_id'] = $msg['project_id'];
##Make project data public
$s3ql = compact('user_id', 'db');
$s3ql['insert'] = 'user';
$s3ql['where']['project_id'] = $user_proj['project_id'];
$s3ql['where']['user_id'] = '2';
$s3ql['where']['permission_level'] = 'nnnynn';
$s3ql['format'] = 'php';
$done = S3QLaction($s3ql);
$msg = unserialize($done);
$msg = $msg[0];
if ($msg['project_id']) {
$user_proj['project_id'] = $msg['project_id'];
}
}
#Collections and Rules
foreach ($important_collections as $name) {
##Now chceck for collections and rule; if there were created as part of the original file project, we don't need to create/check them again
if ($file_fill || !$user_proj[strtolower($name)]['collection_id']) {
$done = array();
$s3ql = compact('user_id', 'db');
$s3ql['from'] = 'collections';
$s3ql['where']['project_id'] = $user_proj['project_id'];
$s3ql['where']['name'] = $name;
$done = S3QLaction($s3ql);
if (!$done[0]['collection_id']) {
$done = array();
$s3ql = compact('user_id', 'db');
$s3ql['insert'] = 'collection';
$s3ql['where']['project_id'] = $user_proj['project_id'];
$s3ql['where']['name'] = $name;
$s3ql['format'] = 'php';
$done = S3QLaction($s3ql);
$msg = unserialize($done);
$msg = $msg[0];
$user_proj[strtolower($name)]['collection_id'] = $msg['collection_id'];
} else {
$user_proj[strtolower($name)]['collection_id'] = $done[0]['collection_id'];
}
}
}
foreach ($important_rules as $subName => $subNameRule) {
foreach ($subNameRule as $ind => $rule_info) {
$done = array();
if ($file_fill || !$user_proj[$rule_info['object']]['rule_id']) {
$s3ql = compact('user_id', 'db');
$s3ql['from'] = 'rules';
$s3ql['where']['project_id'] = $user_proj['project_id'];
$s3ql['where']['subject'] = $subName;
$s3ql['where']['verb'] = $rule_info['verb'];
$s3ql['where']['object'] = $rule_info['object'];
$done = S3QLaction($s3ql);
}
if (!$done[0]['rule_id']) {
$done = array();
$s3ql = compact('user_id', 'db');
$s3ql['insert'] = 'rule';
$s3ql['where']['project_id'] = $user_proj['project_id'];
$s3ql['where']['subject_id'] = $user_proj[strtolower($subName)]['collection_id'];
$s3ql['where']['verb'] = $rule_info['verb'];
if (in_array($rule_info['object'], $important_collections)) {
$s3ql['where']['object_id'] = $user_proj[strtolower($rule_info['object'])]['collection_id'];
} else {
$s3ql['where']['object'] = $rule_info['object'];
}
$s3ql['format'] = 'php';
$done = S3QLaction($s3ql);
$msg = unserialize($done);
$msg = $msg[0];
$user_proj[$rule_info['object']]['rule_id'] = $msg['rule_id'];
$user_proj[strtolower($subName)]['rules'][$ind] = $msg['rule_id'];
$user_proj[strtolower($subName)]['rule_objects'][$ind] = $s3ql['where']['object_id'] != '' ? $s3ql['where']['object_id'] : $s3ql['where']['object'];
//.........这里部分代码省略.........
示例14: array
}
#project rules
$project_rules = array();
$s3ql = compact('user_id', 'db');
$s3ql['from'] = 'rules';
$s3ql['where']['project_id'] = $_REQUEST['project_id'];
$rules = s3list($s3ql);
if (is_array($rules)) {
$project_rules = array_map('grab_rule_id', $rules);
}
#Get all the requests
$s3ql = compact('user_id', 'db');
$s3ql['select'] = '*';
$s3ql['from'] = 'requests';
#echo '<pre>';print_r($s3ql);
$allRequests = S3QLaction($s3ql);
#echo $allRequests;
$MyPending = $allRequests;
if (is_array($MyPending)) {
foreach ($MyPending as $key => $user_request) {
#those requests taht have nothing to do with this project can go
if ($user_request['project_id'] != $_REQUEST['project_id']) {
$MyPending = array_diff_key($MyPending, array($key => ''));
if (in_array($user_request['rule_id'], $project_rules)) {
$myRules[] = $user_request;
}
}
}
}
##Print a list of pending requests
$columns = array('Requested By', 'Project Name', 'Rule_id', 'Rule', 'Notes', 'Status', 'Requested_on', 'Actions');
示例15: apiQuery
function apiQuery($s3ql, $user_proj = false)
{
extract($s3ql);
#if it does not exist, create it and save it in config.inc.php;
if (!$user_proj) {
$user_proj = create_authentication_proj($s3ql['db'], $s3ql['user_id']);
}
if (!$user_proj) {
$msg = "A project to manage users has not been created. This project can only be created by the generic Admin users. Please add your Admin key to apilogin.php to create it automatically.";
return array(false, formatReturn('5', $msg, $format, ''));
exit;
}
if ($s3ql['insert'] != '') {
$target = $s3ql['insert'];
$action = 'insert';
}
if ($s3ql['update'] != '') {
$target = $s3ql['update'];
$action = 'update';
}
if ($s3ql['delete'] != '') {
$target = $s3ql['delete'];
$action = 'delete';
}
if ($s3ql['from'] != '') {
$target = $s3ql['from'];
$action = 'select';
}
if ($target == 'authorities') {
$target = 'authority';
}
if ($action == 'insert') {
switch ($target) {
case 'authentication':
#does the user_id specified exist?
#authentication_id is to always be built from what is provided
$user2add = ereg_replace('^U', '', $s3ql['where']['user_id']);
#validate the authentication inputs
if ($s3ql['where']['authentication_id'] == '') {
if (!$s3ql['where']['authority'] || !$s3ql['where']['username']) {
$msg = formatReturn($GLOBALS['error_codes']['something_missing'], 'Please provide all the necessary fields. These include either <authentication_id> or <protocol>, <authority> and <username>', $_REQUEST['format'], '');
return array(false, $msg);
exit;
} else {
$prot = $s3ql['where']['protocol'];
$auth = $s3ql['where']['authority'];
$email = $s3ql['where']['username'];
$s3ql['where']['authentication_id'] = ($prot != 'http' ? $prot . ':' : '') . $auth . ':' . $email;
$s3ql['where'] = array_delete($s3ql['where'], array('protocol', 'authority', 'username'));
}
}
if ($s3ql['where']['user_id'] == '') {
$s3ql['where']['user_id'] = $user_id;
$user2add = $user_id;
#$msg= (formatReturn($GLOBALS['error_codes']['something_missing'],'Please provide the user_id whose authentication you wish to add.', $format,''));
#return (array(false, $msg));
#exit;
}
#this function will actually validate the authentication feasibility
list($valid, $msg) = validate_authentication($s3ql, $user_id, $db);
if ($valid) {
#does the user_id have an item assigned to him already?
while (!$user_proj['users']['items'][$user2add]['item_id'] && $try < 5) {
$user_proj = insert_authentication_tuple(array('user_proj' => $user_proj, 'user_id' => '1', 'db' => $db, 's3ql' => $s3ql));
#$user_proj = insert_authentication_tuple(compact('user_proj', 'user_id','db','s3ql'));
$try++;
}
if ($user_proj['users']['items'][$user2add]['item_id'] == '') {
$msg = formatReturn($GLOBALS['error_codes']['something_missing'], "Could not create an item for this user.", $format, '');
return array(false, $msg);
exit;
}
#now let's create an statement for this authentication. Since these can be many, we run the query either way and let s3ql tell us whether this already exists
if (!is_array($user_proj[$user2add]['R' . $user_proj['email']['rule_id']])) {
$user_proj[$user2add]['R' . $user_proj['email']['rule_id']] = array();
}
$s3ql_new = compact('user_id', 'db');
$s3ql_new['insert'] = 'statement';
$s3ql_new['where']['rule_id'] = $user_proj['email']['rule_id'];
$s3ql_new['where']['item_id'] = $user_proj['users']['items'][$user2add]['item_id'];
$s3ql_new['where']['value'] = $s3ql['where']['authentication_id'];
$s3ql_new['format'] = 'php';
$done = S3QLaction($s3ql_new);
$msg = unserialize($done);
$msg = $msg[0];
if ($msg['statement_id']) {
array_push($user_proj[$user2add]['R' . $user_proj['email']['rule_id']], $s3ql['where']['authentication_id']);
file_put_contents($GLOBALS['uploads'] . '/userManage.s3db', serialize($user_proj));
$msg1 = formatReturn($GLOBALS['error_codes']['success'], "Authentication inserted", $format, array('authentication_id' => $s3ql['where']['authentication_id']));
return array(false, $msg1);
exit;
} elseif ($msg['error_code'] == '4') {
$msg1 = formatReturn('4', 'The provided authentication already exists for this user.', $format, '');
return array(false, $msg1);
exit;
} elseif ($msg['error_code'] == '11') {
$msg1 = formatReturn('7', 'Invalid authentication format. ' . $msg['message'], $format, '');
return array(false, $msg1);
exit;
} elseif ($msg['error_code'] == '4') {
//.........这里部分代码省略.........