Esempio n. 1
0
function render_inserted_statement_all($I)
{
    extract($I);
    $_SESSION['current_color'] = '0';
    $_SESSION['previous_verb'] = '';
    $instance_id = $instance_info['resource_id'];
    $stats = '';
    if (is_array($rules)) {
        foreach ($rules as $rule_info) {
            $report_msg = '';
            $subject = $rule_info['subject'];
            $verb = $rule_info['verb'];
            $object = $rule_info['object'];
            $rule_id = $rule_info['rule_id'];
            $rule_notes = $rule_info['notes'];
            $notes = $_POST['text_' . $instance_id . '_' . $rule_id];
            $index = $index + 1;
            if (in_array($rule_id, $rule_ids)) {
                #echo 'upload_input_'.$instance_id.'_'.$rule_id.'<BR>';
                #gather data from post
                if ($_FILES['upload_input_' . $instance_id . '_' . $rule_id]['name'] == '') {
                    $value = $_POST['input_' . $instance_id . '_' . $rule_id];
                    if ($value == '') {
                        $value = $_POST['input_' . str_replace('.', '_', $instance_id) . '_' . str_replace('.', '_', $rule_id)];
                    }
                    #insert the statement, run S3QL
                    $s3ql = compact('db', 'user_id');
                    $s3ql['insert'] = 'statement';
                    #$s3ql['where']['project_id'] = $project_id;
                    $s3ql['where']['item_id'] = $instance_id;
                    $s3ql['where']['rule_id'] = $rule_id;
                    $s3ql['where']['value'] = $value;
                    $s3ql['where']['notes'] = $notes;
                    #$s3ql['format']='html';
                    $done = S3QLaction($s3ql);
                    $done = html2cell($done);
                    #ereg('<error>([0-9]+)</error>.*<(message|statement_id)>(.*)</(message|statement_id)>', $done, $s3qlout);
                    $statement_id = $done[2]['statement_id'];
                    $S = compact('user_id', 'rule_info', 'instance_id', 'statement_id', 'value', 'notes', 'db', 'done');
                    if ($done[2]['error_code'] == '0') {
                        $report_msg = render_inserted($s3ql, $statement_id);
                        #$report_msg .= sprintf("%s\n", '		<br /><input type="button" value="Insert Another" onClick="window.location=\''.$action['instanceform'].'\'">');
                        #$report_msg .= sprintf("%s\n", '		<br /><input type="button" value="Close Window" onClick="window.location=\''.$action['instanceform'].'\'">');
                    } else {
                        $report_msg = couldnot_insert_statement($S);
                        #render_statement_already_exists($s3ql);
                    }
                    #elseif($s3qlout[1]=='7')
                    #{
                    #$report_msg = render_resource_doesnot_exist($s3ql);
                    #}
                    #elseif($s3qlout[1]=='3')
                    #{
                    #$report_msg = render_value_cannot_be_null($s3ql);
                    #}
                } else {
                    #project is the same that will go to instance
                    $project_id = $rule_info['project_id'];
                    $value = project_folder_name($project_id, $db);
                    $notes = $_REQUEST['text_' . $instance_id . '_' . $rule_id];
                    $filename = $_FILES['upload_input_' . $instance_id . '_' . $rule_id]['name'];
                    $mimetype = $_FILES['upload_input_' . $instance_id . '_' . $rule_id]['type'];
                    $filesize = filesize($_FILES['upload_input_' . $instance_id . '_' . $rule_id]['tmp_name']);
                    $uploadedfile = $_FILES['upload_input_' . $instance_id . '_' . $rule_id]['tmp_name'];
                    if ($filesize <= 0) {
                        $report_msg = 'Filesize cannot be null';
                    } elseif ($filename == '') {
                        $report_msg = 'Filename cannot be empty';
                    } elseif ($value == '' || $uploadedfile == '') {
                        $report_msg = 'Could not move file, please check with you administrator if file uploads are allowed.';
                    } else {
                        $tmp = fileNameAndExtension($filename);
                        extract($tmp);
                        #write a filekey to send the file by the API
                        $filekey = generateAFilekey(compact('filename', 'extension', 'filesize', 'user_id', 'db'));
                        #move the file like the API would do
                        $file = $uploadedfile;
                        $fileMoved = MoveFile(compact('filekey', 'db', 'file'));
                        #generate a statement_id
                        if ($fileMoved) {
                            $s3ql = compact('db', 'user_id');
                            $s3ql['insert'] = 'file';
                            $s3ql['where']['filekey'] = $filekey;
                            $s3ql['where']['notes'] = $notes;
                            $s3ql['where']['project_id'] = $project_id;
                            $s3ql['where']['rule_id'] = $rule_id;
                            $s3ql['where']['item_id'] = $instance_id;
                            $s3ql['format'] = 'html';
                            $done = S3QLaction($s3ql);
                            $done = html2cell($done);
                            #echo '<pre>';print_r($done);
                            #ereg('<statement_id>([0-9]+)</statement_id>', $done, $s3qlout);
                            $statement_id = $done[2]['file_id'];
                            if ($statement_id != '') {
                                $insert = 'file';
                                $S = compact('rule_id', 'instance_id', 'db', 'insert', 'filename');
                                $report_msg = render_inserted($S, $statement_id);
                            }
                        } else {
                            $report_msg = "<font color='red'>Could not move the file</font>";
                            exit;
                        }
                    }
                }
            } else {
                $report_msg = render_empty_form(compact('index', 'rule_info', 'project_id', 'instance_id', 'db'));
            }
            $finalOutput .= $report_msg;
        }
    }
    //echo $stats;
    return $finalOutput;
}
Esempio n. 2
0
                        $s3ql['where']['item_id'] = $instance_id;
                        $s3ql['format'] = 'html';
                        $done = S3QLaction($s3ql);
                        $msg = html2cell($done);
                        $msg = $msg[2];
                        #ereg('<file_id>([0-9]+)</file_id>', $done, $s3qlout);
                        $statement_id = $msg['file_id'];
                        if ($msg['error_code'] == 0) {
                            $s3ql['file_name'] = $filename;
                            $insert = 'file';
                            $S = compact('rule_id', 'instance_id', 'db', 'insert', 'filename');
                            $report_msg = render_inserted($S, $statement_id);
                            $report_msg .= sprintf("%s\n", '		<br /><input type="button" value="Insert Another" onClick="window.location=\'' . $action['insertstatement'] . '\'">');
                            $report_msg .= sprintf("%s\n", '		&nbsp;&nbsp;<input type="button" value="Close Window" onClick="opener.window.location.reload(); self.close();return false;">');
                        } else {
                            $report_msg = "<font color='red'>" . $msg['message'] . "</font>";
                        }
                    } else {
                        $report_msg = "<font color='red'>Could not move the file</font>";
                    }
                }
            }
        }
        echo $report_msg;
        exit;
    }
}
$index = '1';
echo '<form enctype="multipart/form-data" name="insertstatement" action="' . $action['insertstatement'] . '" method="post" autocomplete="on">';
echo render_empty_form(compact('index', 'rule_info', 'project_id', 'instance_id', 'db', 'user_id'));
echo '<td valign="top"><input name="insert_' . $instance_id . '_' . $rule_id . '" value="Insert" type="submit"></td></tr>';