/s3db3.5.10/s3dbcore/S3QLaction1.php
PHP | 1626 lines | 966 code | 410 blank | 250 comment | 217 complexity | 210e05ea8c9d60cdf21e5e74b414cc74 MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- <?php
- 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
-
- 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')
- {
- $s3ql=ruleInputsInfer($s3ql, $db, $user_id);
- }
- #echo '<pre>';print_r($s3ql);
-
- #translate some s3ql inputs into s3db names:
- #IS there anythi ng still missing? There are 2 types fo required inputs: thsoe from the user and those into the table. The firstare verified here, the rest are verified in "validation"
-
- $diff=array_diff($required[$element],array_keys($s3ql['where']));
-
- if($element_id=='' && !empty($diff))
- return formatReturn($GLOBALS['error_codes']['something_missing'],'Please provide all the necessary fields: '.rtrim(array_reduce($required[$element], "comma_split"), ", ").'. '.$syntax_message, $s3ql['format'], '');
-
-
- #echo '<pre>';print_r($required[$element]);exit;
-
-
- #if there is any sort of id, check if user has permissions on that. In case of statement, permission must be checked on both rule and instance
- $inserteable = array(
- #'deployment'=>'deployment_id',
- 'group'=>'group_id',
- 'user'=>'user_id',
- 'project'=>'project_id',
- 'rule'=>'rule_id',
- 'collection'=>'collection_id',
- 'item'=>'item_id',
- 'statement'=>'statement_id',
-
- );
-
-
- #insert overal view
- #element_id is not empty
- #upstream resource provided
- #if all permissions clear up, grant permission to upper on loewer score;
- #upstream resource not provided
- #infer deployment if user, group or project, else nothing to do
- #element_id is empty
- #upstream resources provided
- #all permissions clear up, create new entry.
-
- #scoreTable will allow us to score the elements according to their position in the inheritance model. To nisert an "inserteable" A into an "inserteable" B,
-
- $scoreTable=array_reverse($inserteable, 0);
-
- $scoreTable = array_combine(array_keys($scoreTable), range(1,count($inserteable)));
-
-
- $elementScore = $scoreTable[$element];#check the score of target. All other score will be chacked against this one
-
- #for user, group and project, inserts occur in deployment (local). Except when there is indication on group or any other Id.
- $input_ids = array_intersect($inserteable, array_keys($s3ql['where']));
-
- if(ereg('^(U|G|P)$', $letter) && (count($input_ids)<=1 || count(array_filter(array_diff_key($s3ql['where'], array($element.'_id'=>''))))==0))
- {
-
- $s3ql['where']['deployment_id']=($s3ql['where']['deployment_id']!='')?$s3ql['where']['deployment_id']:substr($GLOBALS['Did'], 1, strlen($GLOBALS['Did']));
- $info[$GLOBALS['Did']]=URI($GLOBALS['Did'], $user_id, $db);
- $permission2add[$GLOBALS['Did']] = $info[$GLOBALS['Did']]['add_data'];
- $core_score[$GLOBALS['Did']] = 8;
-
-
- }
-
-
- #echo '<pre>';print_r($input_ids);exit;
- #echo '<pre>';print_r($inserteable);
- #echo '<pre>';print_r($s3ql);exit;
- ############################
- #this next segment finds all the s3ids in the query, and checks permission of user/session on it (user/session beause user ccna be using a group)
- #echo '<pre>';print_r($s3ql);
- if (ereg('^(U|G|P|C|R|I|S|F)$', strtoupper(substr($element, 0,1)))) {
-
- foreach ($inserteable as $s3element=>$id) {
-
- if ($s3ql['where'][$id]!='') {
- $element_name = $s3element;
- $id_name = $id;
-
-
- $uid_info=uid(strtoupper(substr($element, 0,1)).$s3ql['where'][$id_name]);
- $element_info = retrieveUIDInfo($s3element, $id, $scoreTable, $s3ql, $letter, $input_ids, $user_id, $db);
- #echo '<pre>';print_r($element_info);
- $info[strtoupper(substr($element_name, 0,1)).$s3ql['where'][$id_name]] = $element_info;
- $permission2add[strtoupper(substr($element_name, 0,1)).$s3ql['where'][$id_name]] = $element_info['add_data'];
- $core_score[strtoupper(substr($element_name, 0,1)).$s3ql['where'][$id_name]] = $scoreTable[$element_name];
-
-
- #when element id is present (customized elemnt-id, and is the only ID, and id already exists, user cannot recreat it. To update it, he must go through update. That is the only ID that can "Not" exist
- if ($id==$GLOBALS['s3ids'][$element] && !is_array($element_info)){
- #if a particular id was not found and user is trying to customize a new element_id, then user will have permission to add to it.
-
- $permission2add[strtoupper(substr($element_name, 0,1)).$s3ql['where'][$id_name]] = '1';
- }
- else
- {
- if(!is_array($element_info) && $uid_info['Did']==$GLOBALS['Did'])#for remote resources, allow insert withour requiring validation.. for now. For inserting projects witha specific uid,
- {
- return (formatReturn($GLOBALS['error_codes']['no_results'], 'Resource '.strtoupper(substr($element_name, 0,1)).$s3ql['where'][$id_name].' was not found', $format,''));
- #if($s3ql['format']=='')
- #return ('<TABLE><TR><TD>error_code</TD><TD>message</TD></TR><TR><TD>'.ereg_replace('[^(0-9)]', '',$GLOBALS['messages']['something_does_not_exist']).'</TD><TD>>Resource '.strtoupper(substr($element_name, 0,1)).$s3ql['where'][$id_name].' was not found</TD></TR></TABLE>');
- #else
- #return ($GLOBALS['messages']['something_does_not_exist'].'<message>Resource '.strtoupper(substr($element_name, 0,1)).$s3ql['where'][$id_name].' was not found</message>');
- }
- }
-
- }
- }
- #echo 'ola<pre>';print_r($info);exit;
- #echo '<pre>';print_r($permission2add);
- #echo '<pre>';print_r($core_score);
- #exit;
-
- $result = array_combine($core_score, $permission2add);#score as index and permissions as values
-
- #a group and a user can be inserted in any one resource... as long as user does have permission on the resource
- if(ereg('^(U|G)$', $letter))
- {
-
- if($result[min(array_keys($result))] || ($user_info['account_type']=='a') && max(array_keys($result))==8)
- $result[max(array_keys($result))]='1';
- }
- $has_permission2add = $result[max(array_keys($result))];#this means the highest scored element does NOT have permission to add
-
-
- #echo '<pre>';print_r($result);exit;
- #how many IDS?Min ID is 1; if two, then it can be inserting a statement or adding remote resource on local resource
- #print $info
-
- ####If any s3ids were found, Variable $info was created, and variable $permission2add was created from the first.
-
- #now,interpret what was found.
- #Permissions need to be checek if any ID is supplied that already exists.
- #if (ereg('(group|user|project|collection|rule|item|statement|file)', $element)) {
- if (ereg('(G|U|P|C|R|I|S|F)', strtoupper(substr($element, 0,1)))) {
-
- if (count($info)=='1' || (count($info)=='2' && $info[$GLOBALS['Did']]!='') || (count($info)=='2' && ereg('^(statement|file)$', $element))) {
-
-
- #is this ID from the element we are trying to insert?
- #does it exist?
-
- if($s3ql['where'][$GLOBALS['COREids'][$element]]!='' && isLocal($uid, $db) && !$info[$uid]['is_remote']) {#cannot recreate id. Do nothing.
- return(formatReturn($GLOBALS['error_codes']['wrong_input'], $uid.' already exists. Could not recreate it.', $format,''));
-
- }
- elseif (count($info)=='1' && $element_id!='') {
-
- return (formatReturn($GLOBALS['error_codes']['something_missing'], 'Please provide the uid where this '.$element.' should be inserted.', $format,''));
- }
-
-
-
- else {
-
- #take inputs, validate them, check permission on ONE id, create resource. Do the switch cases here.
-
-
-
- if($has_permission2add) {
- #this means the highest value on permission2asd is 1.
-
- if($info[$uid]['to_create']=='1' || $element_id=='') {
-
-
- $create_info = $s3ql['where'];
- #echo '<pre>';print_r($create_info); exit;
- #echo 'ola';exit;
- $inputs = gatherInputs(array('element'=>$element, 'info'=>$info,'to_create'=>$create_info, 'user_id'=>$user_id, 'db'=>$db));
- $info=$inputs;
- #echo 'inputs<pre>';print_r($inputs);exit;
- if(!is_array($inputs))
- {
-
- return (formatReturn('3', $inputs, $format,''));
- }
- $validity = validateInputs(compact('element', 'inputs', 'oldvalues', 'info', 'db', 'action', 'key','user_id','format'));
- #echo 'validity<pre>';print_r($validity);exit;
- if($validity[0])
- {
- $key=$s3ql['key'];
- $inserted = insert_s3db(compact('element', 'inputs', 'user_id', 'db', 'key'));
- #echo '<pre>';print_r($inserted);exit;
-
- return (formatReturn('0',$inserted[4], $format, array($element.'_id'=>$inserted[$element.'_id'])));
-
- }
- else {
- #echo '<pre>';print_r($validity);
- return (formatReturn($validity['error_code'],$validity['message'], $format,''));
- }
- }
- elseif($info[$uid]['is_remote']=='1') {#insert the permission on local
- #remote users an dgroups are inserted ON TABLE
- if(ereg('user|group|project', $element))
- {
- #echo '<pre>';print_r($info[$uid]);exit;
- $create_info = $info[$uid];
- $create_info['account_email']=($info[$uid]['account_email']=='')?'s3db@s3db.org':$info[$uid]['account_email'];
- $create_info['account_lid']=($info[$uid]['account_lid']!='')?$info[$uid]['account_lid']:$info[$uid]['account_id'];
-
- $inputs = gatherInputs(array('element'=>$element, 'info'=>$info,'to_create'=>$create_info, 'user_id'=>$user_id, 'db'=>$db));
- #echo '<pre>';print_r($inputs);exit;
- if(!is_array($inputs))
- {return ($inputs);}
-
- $validity = validateInputs(compact('element', 'inputs', 'oldvalues', 'info', 'db', 'action', 'key'));
- #echo '<pre>';print_r($validity);exit;
- if($validity[0])
- { $key=$s3ql['key'];
- $inserted =insert_s3db(compact('element', 'inputs', 'user_id', 'db', 'key'));
-
- return (formatReturn('0', $element.' inserted.', array($element.'_id'=>$inserted[$element.'_id'], $s3ql['format'])));
-
- }
- else {
- return ($validity[1]);
- }
- }
-
- $permission_info = array('uid'=>$uid,'shared_with'=>'U'.$user_id,'permission_level'=>$info[$uid]['acl']);
-
- $permission_added = insert_permission(compact('permission_info', 'db', 'user_id', 'info'));
-
- if(!$permission_added)
- $permission_added = update_permission(compact('permission_info', 'db', 'user_id', 'info'));
- if($permission_added){
- return (formatReturn($GLOBALS['error_codes']['success'], $uid." shared_with in ".$permission_info['shared_with'], $format,''));
- #return $GLOBALS['messages']['success']."<message> ".$uid." shared_with in ".$permission_info['shared_with']."</message>";
- }
- else {
- return (formatReturn($GLOBALS['error_codes']['something_went_wrong'], "Could not share ".$uid." with ".$permission_info['shared_with'], $format,''));
- #return $GLOBALS['messages']['something_went_wrong']."<message>Could not share ".$uid." with ".$permission_info['shared_with']."</message>";
- }
- }
- }
-
- else {
- $no_permission_id = array_search('0', $permission2add);
- return (formatReturn($GLOBALS['error_codes']['no_permission_message'], 'User does not have permission to insert in '.$no_permission_id, $format,''));
- exit;
- #return ($GLOBALS['messages']['no_permission_message'].' Reason: <message>User does not have permission to insert in '.$no_permission_id.'</message>');
- }
-
- }
- }
- elseif(count($info)>=2) #NOT a physical insert, but a virtual insert in an existing resource
- {
-
- #echo '<pre>';print_r($info);exit;
- #2 or + ids in info.
- #these IDS can be entity_id OR membership
-
- if($element_id!='' && !$info[$uid]['to_create']) #this automatically means that the second id refers to membership.
- {
- #grant permissions
-
- $shared_with = array_diff(array_keys($permission2add), array($uid));#take uid from the keys of permission2add, that point to the uid we are sharing with
- $shared_with = $shared_with[0];
-
- $add_resource_on_resource = substr(has_permission(compact('uid', 'shared_with'), $db), 2,1);
-
-
-
- if(!$has_permission2add)#statement has rule_id and instance_id, user must have permission on both.
- return (formatReturn($GLOBALS['error_codes']['no_permission_message'], 'User does not have permission to insert in resource '.key($permission2add), $format,''));
- #return ($GLOBALS['messages']['no_permission_message'].'<message>User does not have permission to insert in resource '.key($permission2add).'</message>');
- if($result[max(array_keys($result))]=='0' && $result[min(array_keys($result))]=='1' && $add_resource_on_resource!='1' && $element!='user')
- return (formatReturn($GLOBALS['error_codes']['something_missing'], 'To share '.$uid.' owner of '.$shared_with.' must insert first '.$uid.' in '.$shared_with.'.', $s3ql['format'], ''));
- else {
- #if is remote and user cna insert in resource, must be inserted first
-
- if($info[$uid]['to_create'])
- {
-
- $create_info = $s3ql['where'];
- #echo '<pre>';print_r($create_info); exit;
- $inputs = gatherInputs(array('element'=>$element, 'info'=>$info,'to_create'=>$create_info, 'user_id'=>$user_id));
-
- if(!is_array($inputs))
- return ($inputs);
-
-
- $validity = validateInputs(compact('element', 'inputs', 'oldvalues', 'info', 'db', 'action', 'key'));
-
-
-
- if($validity[0])
- {
- $key=$s3ql['key'];
- $inserted = insert_s3db(compact('element', 'inputs', 'user_id', 'db', 'key'));
- return (formatReturn('0', $element.' inserted.', array($element.'_id'=>$inserted[$element.'_id'], $s3ql['format'])));
- }
- else {
- return ($validity[1]);
- }
-
- }
- if($info[$uid]['is_remote'])
- {
- #the other iD, non element id, should be the upper ID, where user shoulsd already have intert permission
-
- $diff=array_diff(array_keys($permission2add), array($uid));
- $shared_with = $diff[0];
-
-
- $permission_info = array('uid'=>$uid,'shared_with'=>$shared_with,'permission_level'=>$info[$uid]['acl']);
-
-
- $permission_added = insert_permission(compact('permission_info', 'db', 'user_id', 'info'));
-
- if(!$permission_added)
- $permission_added = update_permission(compact('permission_info', 'db', 'user_id', 'info'));
-
- if($permission_added){
-
- return formatReturn($GLOBALS['error_codes']['success'], $uid." inserted in ".$shared_with, $s3ql['format'], '');
- }
-
- else {
- return (formatReturn($GLOBALS['error_codes']['something_went_wrong'], "Could not share ".$uid." with ".$permission_info['shared_with'], $format,''));
- #return $GLOBALS['messages']['something_went_wrong']."<message>Could not share ".$uid." with ".$permission_info['shared_with']."</message>";
- }
-
- }
- if(!$info[$uid]['to_create'] && $s3ql['where']['permission_level']=='')
- {
- #does it exist already in upper resource?
- $diff=array_diff(array_keys($permission2add), array($uid));
- $shared_with = $diff[0];
-
- $sql = str_replace($GLOBALS['regexp'], '=', select(compact('uid', 'shared_with')));
- #echo $sql;exit;
- $db->query($sql, __LINE__, __FILE__);
-
- if($db->next_record())
- return (formatReturn($GLOBALS['error_codes']['repeating_action'], $uid.' already shared with '.$shared_with.'. You can change its level of permission by indicating permission_level.', $s3ql['format'],''));
- }
- }
-
-
- #share according to permissions
- $uid2share = array_search(min($core_score), $core_score);
- $shared_with = array_search(max($core_score), $core_score);
- $uid_info = uid($uid2share);
-
-
- if(($result[max(array_keys($result))]=='1') || ($add_resource_on_resource && $result[min(array_keys($result))]=='1')) #permission to add on upstream resource
- {
- #echo 'ola';exit;
-
- $case ='2';
- $uid_info = uid($uid2share);
-
- if($uid_info['Did']==$GLOBALS['Did'])
- $uid2share = $uid_info['uid'];
- #$uid2share = strtoupper(substr($uid_info['uid'],0,1)).$GLOBALS['Did'].'/'.$uid_info['uid'];
-
- $permission_info = array('uid'=>$uid2share,
- 'shared_with'=>$shared_with,
- 'permission_level'=>($s3ql['where']['permission_level']!='')?$s3ql['where']['permission_level']:'210',
- );
-
- #echo '<pre>';print_r($permission_info);exit;
-
- $validity = validate_permission(compact('permission_info', 'user_id', 'db', 'info'));#grant project_id permission on rule_id
- #echo $validity;exit;
-
-
-
- if($validity=='0')
- $permission_added = insert_permission(compact('permission_info', 'db', 'user_id', 'info'));#grant rule_id permission on project_id
- elseif($validity=='2')
- $permission_added = update_permission(compact('permission_info', 'db', 'user_id', 'info'));
- elseif($validity=='6' && ereg('^G', $shared_with) && ereg('^U', $uid))
- {
-
- $permission_added = insert_permission(compact('permission_info', 'db', 'user_id', 'info'));#grant rule_id permission on project_id
- $permission_added = update_permission(compact('permission_info', 'db', 'user_id', 'info'));
- }
- #can insert, special case, quick fix
- elseif($validity=='6')
- return (formatReturn($GLOBALS['error_codes']['no_permission_message'], 'User must have permission '.$permission_info['permission_level'].' or greater to grant permission '.$permission_info['permission_level'].' on '.$permission_info['shared_with'], $format,''));
- #return ($GLOBALS['messages']['no_permission_message'].'<message>User must have permission '.$permission_info['permission_level'].' or greater to grant permission '.$permission_info['permission_level'].' on '.$permission_info['shared_with'].'.</message>');
-
-
- }
-
- elseif($result[max(array_keys($result))]=='1' && $result[min(array_keys($result))]=='0') #permission to add on upstream resource
- {
- $case ='1';
-
- if($uid_info['Did']==$GLOBALS['Did'])
- $uid2share= strtoupper(substr($uid_info['uid'],0,1)).$GLOBALS['Did'].'/'.$uid_info['uid'];
-
- $permission_info = array('shared_with'=>$shared_with,
- 'uid'=>$uid2share,
- 'permission_level'=>'001');
-
-
- $permission_added = insert_permission(compact('permission_info', 'db', 'user_id', 'info'));
- if(!$permission_added)
- $permission_added = update_permission(compact('permission_info', 'db', 'user_id', 'info'));
- #This step will leave rule insert pending until owner of the rule comes by and inserts it in project
-
-
- }
-
- if($permission_added)
- {
- #Missing: Create an entry in access_rules with "Pending" statuss
- if($case =='1')
- return (formatReturn($GLOBALS['error_codes']['success'], "Permission on ".$permission_info['uid']." requested and pending.", $format,''));
- #return $GLOBALS['messages']['success']."<message> Permission on ".$permission_info['uid']." requested and pending.</message>";
- else {
- return (formatReturn($GLOBALS['error_codes']['success'],$permission_info['uid']." inserted in ".$permission_info['shared_with'], $s3ql['format'], ''));
- }
-
- }
- else {
- return (formatReturn($GLOBALS['error_codes']['something_went_wrong'], "Could not share ".$permission_info['uid']." with ".$permission_info['shared_with'], $s3ql['format'],''));
- }
-
-
- }
- elseif($info[$uid]['to_create'] || $info[$uid]['is_remote']) {#insert IF is remote or was asserted to be inserted
-
- if(is_array($info[$uid]) && $info[$uid]['is_remote'])
- $create_info = $info[$uid];
- else
- $create_info = $s3ql['where'];
-
-
- $inputs = gatherInputs(array('element'=>$element, 'to_create'=>$create_info, 'user_id'=>$user_id, 'info'=>$info));
-
- #echo '<pre>';print_r($inputs);exit;
- if(!is_array($inputs))
- return ($inputs);
-
- $validity = validateInputs(compact('element', 'inputs', 'oldvalues', 'info', 'db', 'action', 'key'));
-
- if($validity[0])
- { $key=$s3ql['key'];
- $inserted =insert_s3db(compact('element', 'inputs', 'user_id', 'db', 'key'));
-
- return (formatReturn('0', $element.' inserted.', array($element.'_id'=>$inserted[$element.'_id']), $s3ql['format']));
-
- }
- else {
- return ($validity[1]);
- }
-
-
- }
- }
- }
- }
-
-
-
-
- #permissions to add are stored in $permission2add, but when we are inserting an existing idA on an existing idB, we do not need permission to add_data on A, only on B. So the users does not need insert permission on idA, if idA is further down the graph then idB.
- #if there is only 1 id, and there is no insert permission, it can break
-
-
-
- #start some special cases
- switch ($element) {
- case 'key':
- {##INSERT KEY
-
- #when no key is given, generate a random one
- if ($s3ql['where']['key_id']=='')
- $s3ql['where']['key_id'] = random_string('15');
- if($s3ql['where']['expires']=='')
- $s3ql['where']['expires']=date('Y-m-d H:i:s',time() + (1 * 24 * 60 * 60));#expires in 24h
- #user can chose to insert a key for a specific ID, be it group, project, rule or statement (anywhere where permissions can be defined)
-
- $I['inputs'] = array_merge($s3ql['where'], array('account_id'=>$user_id));
-
- $validate = validate_access_key_inputs(array('inputs'=>$I['inputs'], 'db'=>$db, 'user_id'=>$user_id));
-
- switch ($validate)
- {
- case 0:
- {
- return (formatReturn($GLOBALS['error_codes']['something_missing'],'Expiration date is missing', $s3ql['format'], ''));
- break;
- }
- case 1:
- {return (formatReturn($GLOBALS['error_codes']['wrong_input'],'Key is too short. Please input a key longer than 10 char', $s3ql['format'], ''));
- break;
- }
- case 2:
- {return (formatReturn($GLOBALS['error_codes']['wrong_input'],'Invalid date format', $s3ql['format'], ''));
- break;
- }
- case 3:
- {return (formatReturn($GLOBALS['error_codes']['repeating_action'],'Key '.$s3ql['where']['key_id'].' is not valid. Please chose another key', $s3ql['format'], ''));
- break;
- }
- case 4:
- {return (formatReturn($GLOBALS['error_codes']['wrong_input'],'Expiration date must be bigger than present date.', $s3ql['format'], ''));
- break;
- }
-
- case 6:
- {return (formatReturn($GLOBALS['error_codes']['wrong_input'],'UID '.$s3ql['where']['UID'].' does not exist', $s3ql['format'], ''));
- break;
- }
- case 7:
- {return (formatReturn($GLOBALS['error_codes']['no_permission_message'],'UID '.$s3ql['where']['UID'].' does not belong to user.', $s3ql['format'], ''));
- break;
- }
- case 8:
- {return (formatReturn($GLOBALS['error_codes']['wrong_input'],'Please use only numbers and letter in your keys.', $s3ql['format'], ''));
- break;
- }
- case 5:
- {
- add_entry ('access_keys', $I['inputs'], $db);
-
- $output = formatReturn($GLOBALS['error_codes']['success'], 'Key created.',$s3ql['format'], array('key_id'=>$s3ql['where']['key_id']));
-
- return ($output);
-
- }
-
- }
- break;
- }
-
- case 'file':
- {
- $resource_id = ($s3ql['where']['item_id']!='')?$s3ql['where']['item_id']:$s3ql['where']['instance_id'];
- $rule_id = $s3ql['where']['rule_id'];
-
- $filekey = $s3ql['where']['filekey'];
- $notes = $s3ql['where']['notes'];
-
- if($resource_id=='' ||$rule_id=='' ||$filekey=='')
- {
- return (formatReturn($GLOBALS['error_codes']['something_missing'], 'Please provide all the necessary inputs: rule_id, item_id, filekey', $format,''));
- #return ($GLOBALS['messages']['something_missing'].'<message>Please provide all the necessary inputs: rule_id, item_id, filekey</message>');
-
- }
- #Check permission on inserting statements for specific projects
- #Check permission on inserting statements for specific projects
- $rule_info = $info['R'.$rule_id];
- $instance_info = $info['I'.$resource_id];
-
- #$instance_info = URIinfo('I'.$resource_id, $user_id, $key, $db);
-
- if($rule_info['object']=='UID')
- {
- return (formatReturn($GLOBALS['error_codes']['wrong_input'], 'Please use this query only for rules that do NOT enumerate classes. For inserting on other rules, use the query for insert instance', $format, ''));
- #return $wrong_input."<message>Please use this query only for rules that do NOT enumerate classes. For inserting on other rules, use the query for insert instance</message>";
-
- }
- elseif (!is_array($instance_info)) {
- return (formatReturn($GLOBALS['error_codes']['no_results'], 'Item '.$resource_id.' was not found', $format,''));
- #return ($something_does_not_exist.'<message>Instance '.$resource_id.' was not found</message>');
- }
- elseif ($instance_info['resource_class_id']!=$rule_info['subject_id']) {
- return (formatReturn($GLOBALS['error_codes']['wrong_input'],'Subject of rule does match Class of instance',$format,''));
- #return $wrong_input."<message>Subject of rule does match Class of instance</message>";
- }
- elseif($filekey=='')
- return (formatReturn($GLOBALS['error_codes']['something_missing'], 'Please indicate a filekey for this file',$format,''));
- #return $wrong_input."<message>Please indicate a filekey for this file</message>";
-
-
- #Find out if the file already exists in the tmp directory
- $fileFinalName = get_entry('file_transfer', 'filename', 'filekey', $filekey, $db);
- $file_id = get_entry('file_transfer', 'file_id', 'filekey', $filekey, $db);
- ereg('([A-Za-z0-9]+)\.*([A-Za-z0-9]*)$',$fileFinalName, $tokens);
- $name = $tokens[1];
- $extension= $tokens[2];
- #list($name, $extension) = explode('.', $fileFinalName);
- $maindir = $GLOBALS['s3db_info']['server']['db']['uploads_folder'].$GLOBALS['s3db_info']['server']['db']['uploads_file'].'/tmps3db';
-
- $old_file = $maindir.'/'.$file_id.'.'.$extension;
-
- if(!is_file($old_file))
- return (formatReturn($GLOBALS['error_codes']['something_does_not_exist'], 'File not found, please upload file first.', $format,''));
- #return $something_does_not_exist."<message>File not found, please upload file first.</message>";
- else
- {
-
- #project_id will be that of the rule, except if user does not have permission on it.
- $project_info = URI('P'.$rule_info['project_id'], $user_id, $db);
-
- $project_id = ($s3ql['where']['project_id']!='')?$s3ql['where']['project_id']:(($project_info['add_data'])?$class_info['project_id']:'');
- if($project_id =='')
- #find which of the user projects can insert instances in this class.
- {
- $project_id = $rule_info['project_id'];
- #$user_projects = findUserProjects($user_id, $db);
- // $user_projects = array_map('grab_project_id', $user_projects);
- //
- //
- // #find the projects that can access the rule
- // $allowed_projects = array_filter(explode('_', $rule_info['permission']));
- //
- // $both = array_intersect($allowed_projects, $user_projects);
- //
- // if (is_array($both)) {
- // foreach ($both as $key=>$allowed_project_id) {
- // if(substr(has_permission(array('uid'=>'R'.$rule_id, 'shared_with'=>'P'.$allowed_project_id), $db), 2,1))
- // $project_id = $allowed_project_id;
- // }
- // }
- }
-
-
- if($project_id=='')
- return (formatReturn($GLOBALS['error_codes']['something_went_wrong'], 'Failed to find a project_in for this intance', '', $s3ql['format']));
-
- $value = project_folder_name ($project_id, $db);
- $created_by = $user_id;
- $filesize = filesize($old_file);
- $filename = $fileFinalName;
-
- ##Create the row in the statements table
- $create_info = $s3ql['where'];
- #echo '<pre>';print_r($s3ql);
- $inputs = gatherInputs(array('element'=>'file', 'info'=>$info,'to_create'=>$create_info, 'user_id'=>$user_id, 'db'=>$db));
- $info=$inputs;
-
- if(!is_array($inputs))
- {
- return(formatReturn('3', $inputs, $s3ql['format'],''));
- }
- $validity = validateInputs(compact('element', 'inputs', 'oldvalues', 'info', 'db', 'action', 'key','user_id'));
- #echo '<pre>';print_r($validity);exit;
- if($validity[0])
- {
- $key=$s3ql['key'];
- $inserted = insert_s3db(compact('element', 'inputs', 'user_id', 'db', 'key'));
-
- ##Move the file
- $S = compact('user_id', 'project_id', 'resource_id', 'rule_id', 'value', 'notes', 'created_by', 'filename', 'filesize', 'extension', 'db');
- $S['statement_id']=$inserted['statement_id'];
- $S['uploadedfile'] = $old_file;
-
- $fileRelocated = movefile2folder($S);
-
- if(!$fileRelocated)#delete the statement
- {$sql = "delete from s3db_statement where statement_id = '".$S['statement_id']."'";
- $db->query($sql, __FILE__, __LINE__);
- #echo $sql;
- return (formatReturn('2', 'File could not be imported. Please try again.', '', $s3ql['format']));
-
- #unlink($old_file);
- }
- else{
- return (formatReturn($GLOBALS['error_codes']['success'], 'File inserted.', $s3ql['format'], array('file_id'=>$inserted['1'])));
- #if($s3ql['format']=='')
- # return ('<TABLE><TR><TD>error_code</TD><TD>message</TD><TD>'.$element.'_id</TD></TR><TR><TD>'.ereg_replace('[^(0-9)]', '', $inserted[3]).'</TD><TD>'.$inserted[4].'</TD><TD>'.$inserted[$element.'_id'].'</TD></TR></TABLE>');
-
- #else
- # return ($inserted[1]);
- }
-
- }
- else {
- #echo '<pre>';print_r($validity);
- return (formatReturn(ereg_replace('[^(0-9)]', '', $inserted[3]), $validity[1], $format,''));
- #if($s3ql['format']=='')
- # return ('<TABLE><TR><TD>error_code</TD><TD>message</TD></TR><TR><TD>'.ereg_replace('[^(0-9)]', '', $inserted[3]).'</TD><TD>'.$validity[1].'</TD></TR></TABLE>');
- #else
- #return ($validity[1]);
- }
-
- ##Move the file
- if($statement_inserted)
- {
-
- $S['statement_id']=find_latest_UID('statement', $db);
- $S['uploadedfile'] = $old_file;
- $fileRelocated = movefile2folder($S);
- if ($fileRelocated)
- {
-
- return (formatReturn($GLOBALS['error_codes']['success'], "File inserted", array('file_id'=>$S['file_id']), $s3ql['format']));
-
- }
- else {
- return (formatReturn($GLOBALS['error_codes']['something_went_wrong'], 'Failed to move file', $format,''));
- }
- #else return $something_went_wrong."<message>Failed to move file</message>";
-
-
- }
-
- }
-
- #This ends "is not a file"
- }#This ends insert file
- break;
- }#finish element switch
- break;
- } #Finish insert
- case 'edit':
- {
- if($s3ql['edit']=='class')
- $s3ql['edit']='collection';
- if($s3ql['edit']=='instance')
- $s3ql['edit']='item';
- if($s3ql['set']['notes']!='')
- $s3ql['set']['notes'] = utf8_encode($s3ql['set']['notes']);
- if($s3ql['set']['value']!='')
- $s3ql['set']['value'] = utf8_encode($s3ql['set']['value']);
- #$element = $s3ql[$action];
- $element = $s3ql['edit'];
- #echo 'ola<pre>';print_r($s3ql);exit;
- $set = array('project'=>array('project_name', 'project_description', 'project_owner', 'permission_level'),
- 'collection'=>array('project_id', 'entity', 'notes'),
- 'rule'=>array('project_id', 'subject', 'verb', 'object', 'subject_id', 'verb_id', 'object_id', 'notes', 'validation'),
- 'item'=>array('project_id', 'collection_id', 'notes'),
- 'statement'=>array('project_id', 'item_id', 'rule_id', 'value', 'notes'),
- 'user'=>array('account_lid','account_pwd', 'account_uname', 'account_email', 'account_phone', 'addr1', 'addr2', 'account_type', 'city', 'postal_code', 'state', 'country', 'account_status'),
- 'group'=>array('account_lid'));
-
- $E = compact('db', 'user_id', 's3ql');
-
- #first of all, is this a valid target?
- if(!in_array($s3ql['edit'], array_keys($set)))
- {
- return formatReturn($GLOBALS['error_codes']['wrong_input'], $s3ql['edit']." is not a valid S3DB element. Valid elements: project, collection, rule, item, statement", $s3ql['format'],'');
-
- }
-
- #is there an ID to locate the appropriate resource?
- if($s3ql['where'][$element.'_id'] == '')
- {
- return formatReturn($GLOBALS['error_codes']['something_missing'], 'ID of '.$element.' to edit is missing', $s3ql['format'],'');
-
- }
-
- if($s3ql['set']=='')
- {
- #is it in where?
- $s3ql['set']=array_diff_key($s3ql['where'], array($element.'_id'=>''));
- if($s3ql['set']=='')
- return formatReturn($GLOBALS['error_codes']['something_missing'], 'Please specify what you want to update.'.$syntax_message, $s3ql['format'],'');
-
- }
-
- #interpret input
- $s3map=$GLOBALS['s3map'];
-
-
- foreach ($s3map[$GLOBALS['plurals'][$element]] as $alter_name=>$name) {
- if($s3ql['set'][$alter_name]!='')
- $s3ql['set'][$name]=$s3ql['set'][$alter_name];
-
- }
-
- $s3ql['set'] = array_diff_key($s3ql['set'], $s3map[$GLOBALS['plurals'][$element]]);
- $s3ql['set'] = array_filter($s3ql['set']);
-
-
- #detect is something that is something in set that cannot be updated
- $test_set = array_intersect($set[$element], array_keys($s3ql['set']));
- $extra_fields = array_diff(array_keys($s3ql['set']), $test_set);
-
- if(count($s3ql['set'])>count($test_set))#this means that there are fields that don't exist
- foreach ($extra_fields as $field_name) {
-
-
- $output .= '<message>Warning: '.$field_name.' is not a valid property of '.$element.'. '.$field_name.' will not be updated. Valid properties: '.rtrim(array_reduce($set[$element], 'comma_split'), ', ').'</message>';
- }
-
- #retrieve information about resource
- $element_id = $s3ql['where'][$element.'_id'];
- $uid = strtoupper(substr($element,0,1)).$element_id;
- $e_info=URIinfo($uid, $user_id, $key, $db);
- #echo '<pre>';print_r($e_info);
-
- if(!is_array($e_info))
- return (formatReturn($GLOBALS['error_codes']['something_does_not_exist'], ''.$element.' '.$element_id.' was not found.'));
- elseif(!$e_info['change'])
- return (formatReturn($GLOBALS['error_codes']['no_permission_message'], 'User does not have permission to change this '.$element, $s3ql['format'],''));
-
-
- foreach ($e_info as $field=>$data) {
-
- if($s3ql['set'][$field]!='' || $field=='notes')
- if(in_array($field, $set[$element]))
- {
-
- $oldvalues[$field] = $e_info[$field];
- $e_info[$field] = $s3ql['set'][$field];
- $inputs[$field] = $s3ql['set'][$field];
- }
-
- }
-
-
- #echo '<pre>';print_r($inputs);
- switch ($element) {
-
-
- case 'user':{##EDIT USER
- $user_to_change_info = get_info('user', $element_id, $db);#this is necessary because password will not come in the $e_info var.
-
- #permission was checked before the switch
-
- #map values
- $s3map = array('login'=>'account_lid',
- 'password'=>'account_pwd',
- 'username'=>'account_uname',
- 'email'=>'account_email',
- 'phone'=>'account_phone',
- 'address'=>'addr1',
- 'address2'=>'addr2',
- 'city'=>'city',
- 'state'=>'state',
- 'postal_code'=>'postal_code',
- 'country'=>'country',
- 'account_type'=>'account_type');
- #encript the password
-
- #echo '<pre>';print_r($s3ql);exit;
- if ($s3ql['set']['password']!='' || $s3ql['set']['account_pwd']) {
- $s3ql['set']['password'] = ($s3ql['set']['account_pwd']!='')?md5($s3ql['set']['account_pwd']):md5($s3ql['set']['password']);
- }
- else {
- $s3ql['set']['password']=$user_to_change_info['account_pwd'];
- }
- #echo '<pre>';print_r($s3ql);
- #login, password and email cannot be deleted so if they come empty, fill them out with the old values
- $non_erasable = array('login', 'email', 'username', 'password');
-
- foreach ($non_erasable as $fieldname) {
- if (in_array($fieldname, array_keys($s3ql['set']))) {
- if ($s3ql['set'][$fieldname]=='') {
- return (formatReturn($GLOBALS['error_codes']['wrong_input'], 'login, email, username and password cannot be deleted', $s3ql['format'],''));
- }
- }
- elseif (!in_array($fieldname, array_keys($s3ql['set']))) {
- #then start filling out input with the old values
-
- $inputs[$s3map[$fieldname]] = $e_info[$s3map[$fieldname]];
- }
- }
- #now map the valid values
- foreach (array_keys($s3ql['set']) as $set) {
-
- if (in_array($set, array_keys($s3map))) {
-
- if($s3ql['set'][$set]!='') {
-
- $inputs[$s3map[$set]] =$s3ql['set'][$set];
-
- }
- }
-
- }
- #echo '<pre>';print_r($e_info);
- $inputs['account_type'] = ($s3ql['set']['account_type']!='')?$s3ql['set']['account_type']:$user_to_change_info['account_type'];
- $inputs['account_status'] = ($s3ql['set']['account_status']!='')?$s3ql['set']['account_status']:$user_to_change_info['account_status'];
- $inputs['account_group'] = $inputs['account_type'];
-
- #replace in $e_info the values with the inputs. First clean the existing one, then merge with the new one
- $user_info = array_diff_key($e_info, $inputs);
- $user_info = array_merge($user_info, $inputs);
-
-
- $validity = validate_user_inputs(array('inputs'=>$inputs, 'imp_user_id'=>$e_info['account_id'], 'db'=>$db, 'action'=>'update'));
-
- $info=$e_info;
- #echo '<pre>';print_r($inputs);
- #$validity = validateInputs(compact('element','info', 'inputs', 'oldvalues', 'user_id', 'db'));
- #echo '<pre>';print_r($validity);
- switch($validity)
- {
- case 0:
- #echo '<pre>';print_r($user_info); exit;
- if(!update_user(compact('user_info', 'db', 'user_id')))
- {
- #$output .= $something_went_wrong;
- return (formatReturn($GLOBALS['error_codes']['something_went_wrong'], 'User could not be updated. Undetermined reasons.', $s3ql['format'], ''));
- }
- else {
- #$output .= $GLOBALS['messages']['success'];
- #$output .= '<message> User updated</message>';
- return (formatReturn($GLOBALS['error_codes']['success'],'User updated', $s3ql['format'],''));
-
- }
- break;
- case 1:
-
- #$output .= $GLOBALS['messages']['something_missing'];
- #$output .= '<message> Login is missing.'.$syntax_message.'</message>';
- return (formatReturn($GLOBALS['error_codes']['something_missing'], 'Login is missing.'.$syntax_message, $s3ql['format'],''));
- break;
- case 2:
-
- #$output .= $GLOBALS['messages']['something_missing'];
- #$output .= '<message> Account_type is missing.'.$syntax_message.'</message>';
- return (formatReturn($GLOBALS['error_codes']['something_missing'], 'Account_type is missing.'.$syntax_message,$s3ql['format'],''));
- break;
- case 3:
- #$output .= $GLOBALS['messages']['something_missing'];
- #$output .= '<message> Username is missing.'.$syntax_message.'</message>';
- return (formatReturn($GLOBALS['error_codes']['something_missing'], 'Username is missing.'.$syntax_message, $s3ql['format'],''));
- break;
- case 4:
- #$output .= $GLOBALS['messages']['something_missing'];
- #$output .= '<message> Account status is missing.'.$syntax_message.'</message>';
- return (formatReturn($GLOBALS['error_codes']['something_missing'], 'Account status is missing.'.$syntax_message, $s3ql['format'],''));
- break;
- case 5:
- $output .= $GLOBALS['messages']['something_missing'];
- $output .= '<message> Password is missing.'.$syntax_message.'</message>';
- return (formatReturn($GLOBALS['error_codes']['something_missing'], 'Password is missing.'.$syntax_message, $s3ql['format'],''));
- break;
- case 6:
- #$output .= $GLOBALS['messages']['something_missing'];
- return (formatReturn($GLOBALS['error_codes']['something_missing'], '',$s3ql['format'],''));
- break;
- case 7:
- #$output .= $GLOBALS['messages']['something_missing'];
- return (formatReturn($GLOBALS['error_codes']['something_missing'], '',$s3ql['format'],''));
- break;
- case 8:
- #$output .=$GLOBALS['messages']['repeating_action'].'<message> User '.$inputs['account_lid'].' already exists</message>';
- return (formatReturn($GLOBALS['error_codes']['something_missing'], 'User '.$inputs['account_lid'].' already exist',$s3ql['format'],''));
- break;
- }
-
- break;
- }
- case 'group':{##EDIT GROUP
-
- $info = $e_info;
- $group_id = $info['group_id'];
-
- $validity = validateInputs(compact('element', 'inputs', 'oldvalues', 'info', 'db', 'action', 'key'));
- if($validity[0])
- {
- if (update_group(compact('inputs', 'group_id', 'user_id', 'db'))) {
- return (formatReturn($GLOBALS['error_codes']['success'], 'G'.$group_id.' successfully updated',$s3ql['format'],''));
- #return ($GLOBALS['messages']['success'].'<message>G'.$group_id.' successfully updated</message>');
- }
- else {
- return (formatReturn($GLOBALS['error_codes']['something_went_wrong'], 'G'.$group_id.' could not be updated. Reason undetermined.',$s3ql['format'],''));
- #return ($GLOBALS['messages']['something_went_wrong']);
- }
- break;
- }
- else {
- return ($validity[1]);
- }
-
- break;
- }
- case 'project': {##EDIT PROJECT
-
- $project_info = $e_info;
- $U = compact('project_info', 'db', 'user_id');
- #$validity = validate_project_inputs($U);
- $info = $e_info;
- $validity = validateInputs(compact('element', 'inputs', 'oldvalues', 'info', 'db', 'action', 'key'));
- if($validity[0])
- {
- if(update_project($U))
- {
- return formatReturn($GLOBALS['error_codes']['success'], $element." P".$element_id." updated.", $s3ql['format'],'');
-
-
- }
- else
- {
- return formatReturn($GLOBALS['error_codes']['something_went_wrong'], 'Failed to update project!',$s3ql['format'],'');
- }
- }
- else {
- #break validity in error and message
- ereg('<error>([0-9]+)</error>(.*)<message>(.*)</message>', $validity[1], $valOut);
- return (formatReturn($valOut[1],$valOut[3], $s3ql['format'],''));
- }
-
- break;
- }
-
- case 'collection':{##EDIT CLASS
- $resource_info = $e_info;
- $editresource = compact('db','user_id', 'resource_info', 'action', 'inputs', 'oldvalues');
- $info = $e_info;
- $validity = validateInputs(compact('element', 'inputs', 'oldvalues', 'info', 'db', 'action', 'key'));
- #echo '<pre>';print_r($validity);exit;
- #echo $validity = validate_resource_inputs($editresource);exit;
- if($validity[0]){
- if(update_resource($editresource))
- {#$validity[1].'<br><message>'.$element.' updated</message>';
- $output .= formatReturn('0', $element." C".$element_id.' updated', $format, '');
- return ($output);
- #return ($output);
- }
- }
- else {
- ereg('<error>([0-9]+)</error>(.*)<message>(.*)</message>', $validity[1], $valOut);
- return (formatReturn($valOut[1],$valOut[3], $s3ql['format'],''));
- #return ($validity[1]);
- }
-
-
- break;
- }
- case 'item':{##EDIT INSTANCE
-
- #echo '<pre>';print_r($oldvalues);exit;
- #Does this resource exist?
- $instance_id = $element_id;
- $info = $e_info;
- $notes = $s3ql['set']['notes'];
-
- $R = compact('info', 'inputs', 'oldvalues','db', 'user_id');
- $validity = validateInputs(compact('element', 'inputs', 'oldvalues', 'info', 'db', 'action', 'key'));
- if($validity[0]){
- if(update_resource_instance($R))
-
- {
-
- return (formatReturn('0',$element." I".$element_id." updated", $s3ql['format'],''));
-
- #$action = 'edit';
- #$statement_info = $info;
-
- #return ($output);
- }
- }
- else {
- ereg('<error>([0-9]+)</error>(.*)<message>(.*)</message>', $validity[1], $valOut);
- return (formatReturn($valOut[1],$valOut[3], $s3ql['format'],''));
- #return ($validity[1]);
- }
-
-
- break;
- }
-
- case 'rule':##EDIT RULE
- {
-
- $rule_id = $element_id;
- $info = $e_info;
-
- if($info['object']=='UID')
- {
- if($s3ql['where']['subject']!='')
- {#redirect to change class?
-
- $res3ql =array_diff_key($s3ql, array('edit'=>'', 'update'=>''));
- $res3ql['where'] = array_diff_key($res3ql['where'], array('rule_id'=>''));
- $res3ql = array_merge($res3ql, compact('db', 'user_id'));
- $res3ql['edit']='class';
- $res3ql['where']['class_id']=$info['subject_id'];
-
- $done = S3QLaction($res3ql);
-
- return ($done);
- }
- else {
- return (formatReturn($GLOBALS['error_codes']['wrong_input'], 'Rule '.$element_id.' cannot be edited. To change the subject of the relation please use edit class', $s3ql['format']));
- }
- }
- else
- {
- #permission was verified before switch
- if ($s3ql['set']['subject_id']!='') {
-
- #for log, need to keep track of old literal as well.
- $oldvalues['subject'] = $info['subject'];
-
-
- $class_info = s3info('class', $s3ql['set']['subject_id'], $db);
- if (!is_array($class_info)) {
- return (formatReturn($GLOBALS['error_codes']['something_does_not_exist'], 'Class '.$s3ql['set']['subject_id'].' does not exist', $format,''));
- #return ($something_does_not_exist.'<message>Class '.$s3ql['set']['subject_id'].' does not exist</message>');
- }
- $info['subject_id'] = $s3ql['set']['subject_id'];
- $info['subject']=$class_info['entity'];
- }
- else {
- if ($s3ql['set']['subject']!='') {
- …
Large files files are truncated, but you can click here to view the full file