/** * @param $edit_page * @param $obsolete_flag */ function print_versions($edit_page, $obsolete_flag) { $specmanagement_database_api = new specmanagement_database_api(); $specmanagement_print_api = new specmanagement_print_api(); $obsolote = false; if ($obsolete_flag) { $obsolote = null; } if ($edit_page) { $versions = version_get_all_rows_with_subs(helper_get_current_project(), null, null); } else { $versions = version_get_all_rows_with_subs(helper_get_current_project(), null, $obsolote); } for ($version_index = 0; $version_index < count($versions); $version_index++) { $version = $versions[$version_index]; $current_type = $specmanagement_database_api->get_type_string($specmanagement_database_api->get_type_by_version($version['id'])); $specmanagement_print_api->printRow(); echo '<input type="hidden" name="version_ids[]" value="' . $version['id'] . '"/>'; print_name($edit_page, $version); print_released($edit_page, $version_index, $version); print_obsolete($edit_page, $version_index, $version); print_date($edit_page, $version); print_type($edit_page, $current_type, $version); print_description($edit_page, $version); print_action($edit_page, $version); echo '</tr>'; } }
/** FINALIZE UPDATE FIRMWARE TASK * * @param $tid - TASK ID * @param $status - TASK STATUS (STOPPED - PERFORMED) * **/ function finalize_mesh($tid, $status) { //global $log; //$log->info('Task #'.$tid.' mesh '.$status); //$log->info('Task #'.$tid.' start finalizing'); //LOAD DB $db = new Database(); //GET TASK $task = $db->query('select * from sys_tasks where id=' . $tid); //GET TASK ATTRIBUTES $attributes = json_decode($task['attributes'], TRUE); //MOVE OUTPUT FILE TO OBJECT FOLDER $_id_object = $attributes['id_object']; $id_file = $attributes['id_new_file']; $_output = $attributes['output']; $_output_file_name = get_name($_output); $_output_extension = get_file_extension($_output); $_output_folder_destination = '/var/www/upload/' . str_replace('.', '', $_output_extension) . '/'; $_output_file_name = set_filename($_output_folder_destination, $_output_file_name); // MOVE TO FINALLY FOLDER shell_exec('sudo cp ' . $_output . ' ' . $_output_folder_destination . $_output_file_name); // ADD PERMISSIONS shell_exec('sudo chmod 746 ' . $_output_folder_destination . $_output_file_name); // INSERT RECORD TO DB $data_file['file_name'] = $_output_file_name; $data_file['file_path'] = $_output_folder_destination; $data_file['full_path'] = $_output_folder_destination . $_output_file_name; $data_file['raw_name'] = str_replace($_output_extension, '', $_output_file_name); $data_file['client_name'] = str_replace($_output_extension, '', $_output_file_name); $data_file['orig_name'] = $_output_file_name; $data_file['file_ext'] = $_output_extension; $data_file['file_size'] = filesize($_output_folder_destination . $_output_file_name); $data_file['print_type'] = print_type($_output_folder_destination . $_output_file_name); $data_file['note'] = 'Reconstructed on ' . date("F j, Y, g:i a"); $data_file['insert_date'] = 'now()'; $data_file['file_type'] = 'application/octet-stream'; // ADD TASK RECORD TO DB $db->update('sys_files', array('column' => 'id', 'value' => $id_file, 'sign' => '='), $data_file); // ADD ASSOCIATION OBJ FILE $data['id_obj'] = $_id_object; $data['id_file'] = $id_file; $id_ass = $db->insert('sys_obj_files', $data); $db->close(); //UPDATE TASK update_task($tid, $status); sleep(10); //REMOVE ALL TEMPORARY FILES shell_exec('sudo rm -rf ' . $attributes['folder']); //$log->info('Task #'.$tid.' end finalizing'); }
/** */ function copy_from_usb($file) { /** LOAD FILE HELPER */ $this->load->helper('file'); $this->load->helper('ft_file_helper'); $file_name = explode("/", $file); $file_name = end($file_name); /** MOVE TO TEMP FOLDER */ $_command = 'sudo cp "' . $file . '" "/var/www/temp/' . $file_name . '" '; shell_exec($_command); $file = '/var/www/temp/' . $file_name; $file_information = get_file_info($file); $file_extension = get_file_extension($file); $folder_destination = '/var/www/upload/' . str_replace('.', '', $file_extension) . '/'; $file_name = set_filename($folder_destination, $file_name); /** MOVE TO FINALLY FOLDER */ $_command = 'sudo cp "' . $file . '" "' . $folder_destination . $file_name . '" '; shell_exec($_command); /** ADD PERMISSIONS */ $_command = 'sudo chmod 746 "' . $folder_destination . $file_name . '" '; shell_exec($_command); /** INSERT RECORD TO DB */ //carico X class database $this->load->database(); $this->load->model('files'); $data['file_name'] = $file_name; $data['file_path'] = $folder_destination; $data['full_path'] = $folder_destination . $file_name; $data['raw_name'] = str_replace($file_extension, '', $file_name); $data['orig_name'] = $file_name; $data['file_ext'] = $file_extension; $data['file_size'] = $file_information['size']; $data['print_type'] = print_type($folder_destination . $file_name); /** REMOVE TEMP FILE */ unlink($file); /** RETURN */ return $this->files->insert_file($data); }
/** CONNECT DATABASE */ $db = new Database(); /** CHECK FOR OBJ OR CREATE IT */ $cmd = "SELECT id FROM sys_objects WHERE obj_name='Slic3r Upload' AND user={$api_user}"; $obj_id = $db->query($cmd)['id']; if (!$obj_id) { $_obj_insert['obj_name'] = "Slic3r Upload"; $_obj_insert['obj_description'] = "Objects uploaded from Slic3r"; $_obj_insert['private'] = "false"; $_obj_insert['date_insert'] = 'now()'; $_obj_insert['user'] = $api_user; $obj_id = $db->insert('sys_objects', $_obj_insert); } $_file_id = $db->insert('sys_files', array()); /** GET TYPE OF PRINT */ $_print_type = print_type($uploadfile); $_file_size = filesize($uploadfile); /** UPDATE FILE INFO */ $_file_update['file_name'] = $_file_name; $_file_update['file_type'] = 'text/plain'; $_file_update['file_path'] = $_file_path; $_file_update['full_path'] = $uploadfile; $_file_update['raw_name'] = $_raw_name; $_file_update['orig_name'] = $_origin_name; $_file_update['client_name'] = $_origin_name; $_file_update['file_ext'] = '.' . $_extension; $_file_update['file_size'] = $_file_size; $_file_update['print_type'] = $_print_type; $_file_update['insert_date'] = 'now()'; $db->update('sys_files', array('column' => 'id', 'value' => $_file_id, 'sign' => '='), $_file_update); //** ADD FILE TO OBJ */
<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/lib/config.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/lib/database.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/lib/utilities.php'; $_file_path = $_POST["file_path"]; $_file_content = urldecode($_POST["file_content"]); /** SAVE FILE */ file_put_contents($_file_path, $_file_content, FILE_USE_INCLUDE_PATH); $_response_items['success'] = true; /** GET TYPE OF PRINT */ $_print_type = print_type($_file_path); /** SAVE NEW SIZE TO DB */ $db = new Database(); /** UPDATE DATA INFO */ $_data_update['file_size'] = $_file_size; $_data_update['print_type'] = $_print_type; $db->update('sys_files', array('column' => 'id', 'value' => $_file_id, 'sign' => '='), $_data_update); $db->close(); /** JSON RESPONSE */ echo json_encode($_response_items);