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
function file2statement($toMove, $db, $user_id)
{
    extract($toMove);
    $filekey = generateAFilekey(array('filename' => $file, 'filesize' => filesize($file), 'db' => $db, 'user_id' => $user_id));
    $filedata = get_filekey_data($filekey, $db);
    $maindir = $GLOBALS['s3db_info']['server']['db']['uploads_folder'] . $GLOBALS['s3db_info']['server']['db']['uploads_file'];
    $folder = project_folder_name($project_id, $db);
    $tmp = fileNameAndExtension($file);
    extract($tmp);
    $newSpot = $maindir . '/tmps3db/' . $filedata['file_id'] . '.' . $extension;
    #$newSpot = ereg_replace('/.$','',$newSpot);
    copy($file, $newSpot);
    $s3ql = compact('user_id', 'db');
    $s3ql['insert'] = 'file';
    $s3ql['where']['filekey'] = $filekey;
    $s3ql['where']['rule_id'] = $rule_id;
    $s3ql['where']['item_id'] = $item_id;
    #echo '<pre>';print_r($s3ql);exit;
    $fileinserted = S3QLaction($s3ql);
    #echo '<pre>';print_r($fileinserted);exit;
    $fileinserted = html2cell($fileinserted);
    if ($fileinserted[2]['error_code'] == '0') {
        return $fileinserted[2]['file_id'];
    } else {
        return False;
    }
}
Esempio n. 3
0
     #$message = "Value cannot be empty";
 } else {
     $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', 'filesize', 'db', 'user_id'));
         #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'] = trim($notes);
             $s3ql['where']['rule_id'] = $rule_id;
             $s3ql['where']['item_id'] = $instance_id;
             $s3ql['format'] = 'html';
Esempio n. 4
0
function fileLocation($statement_info, $db)
{
    $maindir = $GLOBALS['s3db_info']['server']['db']['uploads_folder'] . $GLOBALS['s3db_info']['server']['db']['uploads_file'];
    #retrieve the project information
    $folder_code_name = project_folder_name($statement_info['project_id'], $db);
    $file_name = $statement_info['file_name'];
    #echo '<pre>';print_r($statement_info);
    #list ($realname, $extension) = explode('.', $file_name);
    $tmp = fileNameAndExtension($file_name);
    $realname = $tmp['name'];
    $extension = $tmp['extension'];
    $file_new_name = $realname . '_' . urlencode($statement_info['project_id'] . '_' . $statement_info['resource_id'] . '_' . $statement_info['rule_id'] . '_' . $statement_info['statement_id']) . '.' . $extension;
    $file_location = $maindir . "/" . $folder_code_name . "/" . $file_new_name;
    return $file_location;
}
Esempio n. 5
0
function pushDownload2Header($Z)
{
    extract($Z);
    $maindir = $GLOBALS['s3db_info']['server']['db']['uploads_folder'] . $GLOBALS['s3db_info']['server']['db']['uploads_file'];
    #retrieve the project information
    #$project_id =  $statement_info['project_id'];
    #$project_info = URI('P'.$project_id, $user_id, $db);
    $folder_code_name = $statement_info['project_folder'];
    $file_name = urlencode($statement_info['file_name']);
    #list ($realname, $extension) = explode('.', $file_name);
    $tmp = fileNameAndExtension($file_name);
    #echo '<pre>';print_r($tmp);exit;
    extract($tmp);
    //echo $realname;exit;
    $file_new_name = $name . '_' . urlencode($statement_info['project_id'] . '_' . $statement_info['resource_id'] . '_' . $statement_info['rule_id'] . '_' . $statement_info['statement_id']) . '.' . $extension;
    $file_location = $maindir . "/" . $folder_code_name . "/" . $file_new_name;
    #echo $file_location.is_file($file_location);exit;
    #echo $file_location;exit;
    if (is_file($file_location)) {
        $file_handle = fopen($file_location, "r");
    } else {
        echo formatReturn($GLOBALS['error_codes']['something_went_wrong'], 'This file does not exist', $format, '');
        exit;
    }
    $file_name = urlencode($file_name);
    #echo 'download in progress';
    $size = filesize($file_location) ? filesize($file_location) : '1';
    $file_contents = fread($file_handle, $size);
    if ($_REQUEST['download'] != 'no' && $_REQUEST['download'] != '0' && $_REQUEST['download'] != 'false') {
        header("Pragma: public");
        header("Expires: 0");
        // set expiration time
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        // browser must download file from server instead of cache
        // force download dialog
        header("Content-Type: application/force-download");
        header("Content-Type: application/octet-stream");
        header("Content-Type: application/download");
        #header("Content-Type: ".$ext."");
        // use the Content-Disposition header to supply a recommended filename and
        // force the browser to display the save dialog.
        header("Content-Disposition: attachment; filename=" . $file_name . "");
        header("Content-Transfer-Encoding: binary");
        echo $file_contents;
    } else {
        //encode the string when the format output is json
        if ($_REQUEST['callback'] || $_REQUEST['format'] == 'json') {
            $callback = $_REQUEST['jsonp'] == '' ? $_REQUEST['callback'] == '' ? 's3db_json' : $_REQUEST['callback'] : $_REQUEST['jsonp'];
            $onLoad = $_REQUEST['onload'] == '' ? '' : '; ' . stripslashes($_REQUEST['onload']) . (ereg('\\(.*\\)', $_REQUEST['onload']) ? '' : '()');
            $jsonpp = $_REQUEST['jsonpp'] == '' ? '' : ', "' . $_REQUEST['jsonpp'] . '"';
            $datatype = $_REQUEST['datatype'] != "" ? $_REQUEST['datatype'] : 'string';
            if ($datatype == 'string') {
                $st = '"';
                $en = '"';
            } elseif ($datatype == 'numeric') {
                $st = '[';
                $file_contents = str_replace(" ", ",", $file_contents);
                $en = ']';
            }
            if ($datatype != 'numeric' && $datatype != 'var') {
                $file_contents = urlencode($file_contents);
            }
            $string2out = $callback . '(' . $st . $file_contents . $en . $jsonpp . ')' . $onLoad;
            #$string2out = $callback.'('.'"'.urlencode($file_contents).'"'.$jsonpp.')'.$onLoad;
        } else {
            $string2out = $file_contents;
        }
        echo $string2out;
    }
    fclose($file_handle);
}