コード例 #1
0
 function submit_upload($array = NULL)
 {
     global $eh, $Cbucket, $db, $userquery;
     if (!$array) {
         $array = $_POST;
     }
     $this->validate_video_upload_form($array, TRUE);
     if (empty($eh->error_list)) {
         $required_fields = $this->loadRequiredFields($array);
         $location_fields = $this->loadLocationFields($array);
         $option_fields = $this->loadOptionFields($array);
         $upload_fields = array_merge($required_fields, $location_fields, $option_fields);
         //Adding Custom Upload Fields
         if (count($this->custom_upload_fields) > 0) {
             $upload_fields = array_merge($upload_fields, $this->custom_upload_fields);
         }
         //Adding Custom Form Fields
         if (count($this->custom_form_fields) > 0) {
             $upload_fields = array_merge($upload_fields, $this->custom_form_fields);
         }
         $userid = userid();
         if (!userid() && has_access('allow_video_upload', true, false)) {
             $userid = $userquery->get_anonymous_user();
             //$userid = $user['userid'];
         } elseif (userid() && !has_access('allow_video_upload', true, true)) {
             return false;
         }
         if (is_array($_FILES)) {
             $array = array_merge($array, $_FILES);
         }
         foreach ($upload_fields as $field) {
             $name = formObj::rmBrackets($field['name']);
             $val = $array[$name];
             if ($field['use_func_val']) {
                 $val = $field['validate_function']($val);
             }
             if (!empty($field['db_field'])) {
                 $query_field[] = $field['db_field'];
             }
             if (is_array($val)) {
                 $new_val = '';
                 foreach ($val as $v) {
                     $new_val .= "#" . $v . "# ";
                 }
                 $val = $new_val;
             }
             if (!$field['clean_func'] || !apply_func($field['clean_func'], $val) && !is_array($field['clean_func'])) {
                 $val = mysql_clean($val);
             } else {
                 $val = apply_func($field['clean_func'], sql_free($val));
             }
             if (empty($val) && !empty($field['default_value'])) {
                 $val = $field['default_value'];
             }
             if (!empty($field['db_field'])) {
                 $query_val[] = $val;
             }
         }
         //Adding Video Code
         $query_field[] = "file_name";
         $file_name = mysql_clean($array['file_name']);
         $query_val[] = $file_name;
         //ADding Video Key
         $query_field[] = "videokey";
         $query_val[] = $this->video_keygen();
         //Userid
         $query_field[] = "userid";
         if (!$array['userid']) {
             $query_val[] = $userid;
         } else {
             $query_val[] = $array['userid'];
         }
         //Upload Ip
         $query_field[] = "uploader_ip";
         $query_val[] = $_SERVER['REMOTE_ADDR'];
         $activation = ACTIVATION;
         //Setting Activation Option
         if ($activation == 0) {
             $active = 'yes';
         } else {
             $active = 'no';
         }
         $query_field[] = "active";
         $query_val[] = $active;
         $query_field[] = "date_added";
         $query_val[] = now();
         $query_field[] = 'file_directory';
         $query_val[] = $array['file_directory'];
         /*$query = "INSERT INTO " . tbl("video") . " (";
                     $total_fields = count($query_field);
         
                     //Adding Fields to query
                     $i = 0;
                     foreach ($query_field as $qfield) {
                         $i++;
                         $query .= $qfield;
                         if ($i < $total_fields)
                             $query .= ',';
                     }
         
                     $query .= ") VALUES (";
         
         
                     $i = 0;
                     //Adding Fields Values to query
                     foreach ($query_val as $qval) {
                         $i++;
                         $query .= "'$qval'";
                         if ($i < $total_fields)
                             $query .= ',';
                     }
         
                     //Finalzing Query
                     $query .= ")";
                     */
         $the_fields = array();
         $total_fields = count($query_field);
         for ($i = 0; $i < $total_fields; $i++) {
             $the_fields[$query_field[$i]] = $query_val[$i];
         }
         //exit($query);
         if (!userid() && !has_access('allow_video_upload', false, false)) {
             e(lang("you_not_logged_in"));
             //exit();
         } else {
             $insert_id = file_name_exists($file_name);
             if (!$insert_id) {
                 //$db->Execute($query);
                 $insert_id = db_insert(tbl('video'), $the_fields);
                 //loggin Upload
                 $log_array = array('success' => 'yes', 'action_obj_id' => $insert_id, 'userid' => $userid, 'details' => "uploaded a video");
                 insert_log('upload_video', $log_array);
                 $db->update(tbl("users"), array("total_videos"), array("|f|total_videos+1"), " userid='" . $userid . "'");
             }
         }
     }
     //Adding Video Feed
     //addFeed(array('action' => 'upload_video', 'object_id' => $insert_id, 'object' => 'video'));
     return $insert_id;
 }
コード例 #2
0
function test_import_excel($test_id, $name)
{
    global $db;
    $ts_tbl = TEST_STEP_TBL;
    $f_ts_id = TEST_STEP_ID;
    $f_ts_test_id = TEST_STEP_TEST_ID;
    $f_ts_step_no = TEST_STEP_NO;
    $f_ts_action = TEST_STEP_ACTION;
    $f_ts_input = TEST_STEP_TEST_INPUTS;
    $f_ts_expected = TEST_STEP_EXPECTED;
    $f_info_step = TEST_STEP_INFO_STEP;
    $s_project_properties = session_get_project_properties();
    $project_name = $s_project_properties['project_name'];
    $redirect_on_error = "test_step_import_csv_page.php?test_id={$test_id}";
    $uploaded_file = $_FILES[$name];
    $file_name = $_FILES[$name]['name'];
    $file_temp_name = $_FILES[$name]['tmp_name'];
    $file_size = $_FILES[$name]['size'];
    /*
    print"file_name = $file_name<br>";
    print"file_temp_name = $uploaded_file[tmp_name]<br>";
    print"file_size = $uploaded_file[size]<br>";
    */
    if ($file_size != '0' && is_uploaded_file($file_temp_name)) {
        require_once './Excel/reader.php';
        // ExcelFile($filename, $encoding);
        $data = new Spreadsheet_Excel_Reader();
        // Set output Encoding.
        $data->setOutputEncoding('CP1251');
        /***
         * if you want you can change 'iconv' to mb_convert_encoding:
         * $data->setUTFEncoder('mb');
         *
         **/
        /***
         * By default rows & cols indeces start with 1
         * For change initial index use:
         * $data->setRowColOffset(0);
         *
         **/
        /***
         *  Some function for formatting output.
         * $data->setDefaultFormat('%.2f');
         * setDefaultFormat - set format for columns with unknown formatting
         *
         * $data->setColumnFormat(4, '%.3f');
         * setColumnFormat - set format for column (apply only to number fields)
         *
         **/
        $data->read($uploaded_file['tmp_name']);
        //error_reporting(E_ALL ^ E_NOTICE);
        $debug = false;
        if (!$debug) {
            $q = "DELETE FROM {$ts_tbl} WHERE {$f_ts_test_id} = '{$test_id}'";
            db_query($db, $q);
        }
        for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) {
            $step_no = '';
            $action = '';
            $test_input = '';
            $expected = '';
            $info = '';
            //for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) {
            //echo "\"".$data->sheets[0]['cells'][$i][1]."\",";
            /*
            print"i = $i<br>";
            	print"j = $j<br>";
            */
            # Get record from CSV file
            $step_no = @util_html_special_chars_string($data->sheets[0]['cells'][$i][1]);
            $action = @util_html_special_chars_string($data->sheets[0]['cells'][$i][2]);
            $test_input = @util_html_special_chars_string($data->sheets[0]['cells'][$i][3]);
            $expected = @util_html_special_chars_string($data->sheets[0]['cells'][$i][4]);
            $info = @util_html_special_chars_string($data->sheets[0]['cells'][$i][5]);
            # We don't need to insert the column headers
            if ($i > 1) {
                # Insert into the Test Set table
                $q = "\tINSERT INTO {$ts_tbl}\n\t\t\t\t\t\t( {$f_ts_test_id}, {$f_ts_step_no}, {$f_ts_action}, {$f_ts_input}, {$f_ts_expected}, {$f_info_step} )\n\t\t\t\t\tVALUES\n\t\t\t\t\t\t( '{$test_id}', '{$step_no}', '{$action}', '{$test_input}', '{$expected}', '{$info}' )";
                if ($debug) {
                    print "{$q};<br>";
                } else {
                    db_query($db, $q);
                }
            }
        }
        # Create a version of the file in Test Doc Version table if the upload was successful
        if (file_name_exists($test_id, $file_name)) {
            # Get the manual_test_id from the Manual Test Doc table and add a new file version
            $manual_test_id = test_get_manual_test_id($test_id, $file_name);
            file_add_supporting_test_doc_version($file_temp_name, $file_name, $test_id, $manual_test_id, $comments = "", $file_type = "");
        } else {
            # Add a new file
            file_add_supporting_test_doc($file_temp_name, $file_name, $test_id, $comments = "", $file_type = "");
        }
    } else {
        # The user tried to upload and empty file
        error_report_show($redirect_on_error, NO_FILE_SPECIFIED);
    }
}
コード例 #3
0
function file_add_supporting_test_doc_version($file_temp_name, $file_name, $test_id, $manual_test_id, $comments, $file_type)
{
    global $db;
    $project_properties = session_get_project_properties();
    $file_upload_path = $project_properties['test_upload_path'];
    $project_id = $project_properties['project_id'];
    $redirect_page = "test_detail_page.php?test_id={$test_id}&project_id={$project_id}&tab=2";
    $redirect_on_error = "test_add_doc_version_page.php?test_id={$test_id}&manual_test_id={$manual_test_id}";
    $file_db_name = "";
    # Check to make sure the file name is the same as the previous version
    if (IGNORE_VERSION_FILENAME_VALIDATION || file_name_exists($test_id, $file_name)) {
        # create a unique name for the file using the time function
        $file_db_name = "SupportingTestDoc" . time() . "-{$file_name}";
        # Get the current file version and increment it by one
        $current_file_version = test_get_max_file_version($manual_test_id);
        $file_version = util_increment_version($current_file_version);
        # Make sure the temp file was uploaded successfully
        if (move_uploaded_file($file_temp_name, $file_upload_path . $file_db_name)) {
            $current_date = date("Y-m-d H:i:s");
            $s_user = session_get_user_properties();
            $username = $s_user['username'];
            $td_vers_tbl = MAN_TD_VER_TBL;
            $f_man_test_id = MAN_TD_VER_MANUAL_TEST_ID;
            $f_file_name = MAN_TD_VER_FILENAME;
            $f_timestamp = MAN_TD_VER_TIME_STAMP;
            $f_version = MAN_TD_VER_VERSION;
            $f_username = MAN_TD_VER_UPLOADED_BY;
            $f_comments = MAN_TEST_DOCS_VERS_COMMENTS;
            $f_file_type = MAN_TEST_DOCS_VERS_MANUAL_DOC_TYPE_NAME;
            $q = "INSERT INTO {$td_vers_tbl} \n\t\t\t\t({$f_man_test_id}, {$f_file_name}, {$f_timestamp}, {$f_version}, {$f_username}, {$f_comments}, {$f_file_type}) \n\t\t\t\tVALUES ('{$manual_test_id}', '{$file_db_name}', '{$current_date}', '{$file_version}', '{$username}', '{$comments}', '{$file_type}')";
            //print"$q<br>";
            $db->Execute($q);
        } else {
            # The file wasn't uploaded to the temp directory successfully
            error_report_show($redirect_page, FAILED_FILE_UPLOAD);
        }
    } else {
        # The file name of the new version doesn't match the old
        error_report_show($redirect_on_error, NO_MATCHING_FILE_NAME);
    }
}