/** * List all the users. * * It receives 2 post parameters with ajax call for user filteration * * @return settings/user view */ public function users() { $data['current_role'] = $currentRoleID = $this->role_id; $data['is_ajax'] = FALSE; $roles = $this->roles->get_roles_list($currentRoleID)->result(); $params = null; if (isAjax()) { $data['is_ajax'] = TRUE; $params = array('station_id' => $this->input->post('station_id'), 'role_id' => $this->input->post('role_id')); } $data['users'] = $this->users->get_users($currentRoleID, $params)->result(); $data['roles'][''] = 'Select'; $data['stations'][''] = 'Select'; foreach ($roles as $value) { $data['roles'][$value->id] = $value->name; } $stations = $this->station_model->get_all(); foreach ($stations as $value) { $data['stations'][$value->id] = $value->station_name; } if (isAjax()) { echo $this->load->view('settings/user', $data, TRUE); exit_function(); } $this->load->view('settings/user', $data); }
function third() { enter_function('third'); second(); first(); exit_function(); }
/** * Make query for exporting the AMS Refine and insert in database * * @param string $type * * @return json with message */ public function export($type) { if ($type == 'instantiation') { $query = $this->refine_modal->export_refine_csv(TRUE); $record = array('user_id' => $this->user_id, 'is_active' => 1, 'export_query' => $query, 'refine_type' => 'instantiation'); $job_id = $this->refine_modal->insert_job($record); } else { $query = $this->refine_modal->export_asset_refine_csv(TRUE); $record = array('user_id' => $this->user_id, 'is_active' => 1, 'export_query' => $query, 'refine_type' => 'asset'); $job_id = $this->refine_modal->insert_job($record); } echo json_encode(array('msg' => 'You will receive an email containing the link for AMS Refine.')); exit_function(); }
/** * Insert Assets information to Sphnix Realtime Index. * * @return none */ function insert_assets_sphnix() { set_time_limit(0); @ini_set("memory_limit", "4000M"); # 1GB @ini_set("max_execution_time", 999999999999.0); $db_count = 0; $offset = 0; while ($db_count == 0) { $inst = $this->searchd_model->get_asset($offset, 1000); myLog('Get 1000 records'); $ids = array_map(array($this, 'make_map_array'), $inst); mylog($ids); $records = $this->searchd_model->get_asset_index($ids); myLog('Start inserting to sphinx'); foreach ($records as $row) { $data = make_assets_sphnix_array($row); $this->sphnixrt->insert($this->config->item('asset_index'), $data, $row->id); myLog('Inserted ID =>' . $row->id); } myLog('Inserted 1000 records'); $offset = $offset + 1000; if (count($inst) < 1000) { $db_count++; } } exit_function(); }
function download_file($file_path) { if (!is_readable($file_path)) { die('File not found/unable to read it'); } if (file_exists($file_path)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . basename($file_path)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . filesize($file_path)); ob_clean(); flush(); readfile($file_path); exit_function(); } }
/** * Store all PBCore 2.x directories and data files in the database. * */ function process_dir() { set_time_limit(0); // $this->myLog("Calculating Number of Directories..."); $this->cron_model->scan_directory($this->pbcore_path, $dir_files); $count = count($dir_files); // $this->myLog("Total Directories: $count"); if (isset($count) && $count > 0) { // $this->myLog("Total Number of process: " . $count); $loop_counter = 0; $maxProcess = 5; foreach ($dir_files as $dir) { $cmd = escapeshellcmd('/usr/bin/php ' . $this->config->item('path') . 'index.php pbcore2 pbcore2_dir_child ' . base64_encode($dir)); $this->config->item('path') . "cronlog/pbcore2_dir_child.log"; $pidFile = $this->config->item('path') . "PIDs/pbcore2_dir_child/" . $loop_counter . ".txt"; @exec('touch ' . $pidFile); $this->runProcess($cmd, $pidFile, $this->config->item('path') . "cronlog/pbcore2_dir_child.log"); $file_text = file_get_contents($pidFile); $this->arrPIDs[$file_text] = $loop_counter; $proc_cnt = $this->procCounter(); $loop_counter++; while ($proc_cnt == $maxProcess) { // $this->myLog('Number of Processes running: ' . $loop_counter . '/.' . $count . ' Sleeping ...'); sleep(30); $proc_cnt = $this->procCounter(); } } // $this->myLog("Waiting for all process to complete."); $proc_cnt = $this->procCounter(); while ($proc_cnt > 0) { // echo "Sleeping for 10 second...\n"; sleep(10); echo ""; echo "\n"; $proc_cnt = $this->procCounter(); // echo "Number of Processes running: $proc_cnt/$maxProcess\n"; } } echo "All Data Path Under {$this->pbcore_path} Directory Stored "; exit_function(); }
/** * Save cron to export records in pbcore 2 xml format. * * @return JsonArrayType */ function export_pbcore() { $this->load->model('pbcore_model'); $this->load->model('export_csv_job_model', 'csv_job'); $records = $this->sphinx->assets_listing(0, 1000); $_ids = ''; if ($records['total_count'] <= 1000) { foreach ($records['records'] as $record) { $_ids .= "{$record->id},"; } $query = rtrim($_ids, ','); $query_loop = 0; } else { $query = $this->pbcore_model->export_assets(TRUE); $query_loop = ceil($records['total_count'] / 100000); } $record = array('user_id' => $this->user_id, 'status' => 0, 'type' => 'pbcore', 'export_query' => $query, 'query_loop' => $query_loop); $this->csv_job->insert_job($record); echo json_encode(array('link' => 'false', 'msg' => 'Email will be sent to you with the link to download.')); exit_function(); }
/** * Update the satation start date * * @return json */ public function update_dsd_station() { if (isAjax()) { $dates = $this->input->post(); foreach ($dates as $index => $value) { $station_id = explode('_', $index); $station_id = $station_id[count($station_id) - 1]; $start_date = date('Y-m-d', strtotime($value)); $this->station_model->update_station($station_id, array('start_date' => $start_date)); $this->sphinx->update_indexes('stations', array('start_date'), array($station_id => array((int) strtotime($start_date)))); $log = array('user_id' => $this->user_id, 'record_id' => $station_id, 'record' => 'station', 'type' => 'edit', 'comments' => 'update from digitization start date message.'); $this->audit_trail($log); } echo json_encode(array('success' => TRUE)); exit_function(); } show_404(); }
/** * Update guid for University of Maryland. * */ function update_guid_for_umd() { $assets = $this->assets_model->get_assets_by_station_id(125); foreach ($assets as $key => $value) { $guids = $this->assets_model->get_guid_identifier_by_asset_id($value->id); $guid = $guids->identifier; $explode = explode('cpb-aacip/', $guid); $guid_start = 'cpb-aacip/500-'; $explode = explode('-', $explode[1]); $new_guid = $guid_start . $explode[1]; $this->assets_model->update_identifier_by_id($guids->id, array('identifier' => $new_guid)); } exit_function(); }
/** * Update the user information that received from MINT. * * @return json array. */ public function update_user() { if (isAjax()) { $mint_id = $this->input->post('mint_id'); $user_id = $this->input->post('user_id'); $this->user_profile->set_profile($user_id, array('mint_user_id ' => $mint_id)); echo json_encode(array('success' => 'true')); exit_function(); } show_404(); }
/** * Update the records for AMS Refine records. Also rotate the indexes. * * @return */ function update_refine() { set_time_limit(0); @ini_set("memory_limit", "1000M"); # 1GB @ini_set("max_execution_time", 999999999999.0); # 1GB $record = $this->refine_modal->refine_update_records(); if (count($record) > 0) { if ($record->refine_type === 'instantiation') { $this->update_instantiations($record->import_csv_path, $record->user_id); } else { $this->update_assets($record->import_csv_path, $record->user_id); } $this->refine_modal->update_job($record->id, array('is_active' => 0)); myLog("All Indexes Rotated Successfully."); } else { myLog('No AMS Refine update available.'); } exit_function(); }
/** * Store all mediainfo directories and data files in the database. * */ function process_dir() { @set_time_limit(0); @ini_set("memory_limit", "1000M"); # 1GB @ini_set("max_execution_time", 999999999999.0); # 1GB @error_reporting(E_ALL); @ini_set('display_errors', 1); $this->cron_model->scan_directory($this->media_info_path, $dir_files); $count = count($dir_files); if (isset($count) && $count > 0) { myLog("Total Number of process " . $count); $loop_counter = 0; $maxProcess = 10; foreach ($dir_files as $dir) { $cmd = escapeshellcmd('/usr/bin/php ' . $this->config->item('path') . 'index.php mediainfo process_dir_child ' . base64_encode($dir)); $this->config->item('path') . "cronlog/mediainfo_processdir.log"; $pidFile = $this->config->item('path') . "PIDs/media_info/" . $loop_counter . ".txt"; @exec('touch ' . $pidFile); $this->runProcess($cmd, $pidFile, $this->config->item('path') . "cronlog/mediainfo_processdir.log"); $file_text = file_get_contents($pidFile); $this->arrPIDs[$file_text] = $loop_counter; $proc_cnt = $this->procCounter(); $loop_counter++; while ($proc_cnt == $maxProcess) { myLog('Number of Processes running : ' . $loop_counter . '/.' . $count . ' Sleeping ...'); sleep(30); $proc_cnt = $this->procCounter(); } } myLog("Waiting for all process to complete"); $proc_cnt = $this->procCounter(); while ($proc_cnt > 0) { echo "Sleeping....\n"; sleep(10); echo ""; echo "\n"; $proc_cnt = $this->procCounter(); echo "Number of Processes running : {$proc_cnt}/{$maxProcess}\n"; } } echo "All Data Path Under {$this->media_info_path} Directory Stored "; exit_function(); }
/** * Make xml for PBcore format and output the xml for webservice. * * It receives at least one parameter and page number in uri segments. * Parameters are guid string * Parameters are digitized 0 or 1 * Parameters are modified_date YYYYMMDD * Parameters are page number * * @return void */ function pbcore() { $default = array('key', 'guid', 'digitized', 'modified_date', 'page'); $_uri = $this->uri->uri_to_assoc(3, $default); Header('Content-type: text/xml'); if (!$this->_validate_key($_uri['key'])) { $result = $this->export_pbcore_premis->xml_error('You are not authorize to access web services.'); echo $result->asXML(); exit_function(); } if (isset($_uri['guid']) && !empty($_uri['guid'])) { $result = $this->pbcore_model->get_one_by($this->pbcore_model->table_identifers, array('identifier' => "cpb-aacip/{$_uri['guid']}")); if ($result) { $this->export_pbcore_premis->asset_id = $result->assets_id; $this->export_pbcore_premis->is_pbcore_export = TRUE; $this->export_pbcore_premis->make_xml(); echo $this->export_pbcore_premis->xml->asXML(); } else { $result = $this->export_pbcore_premis->xml_error('Invalid GUID. No record found.'); echo $result->asXML(); } } else { if ($_uri['digitized'] != '' || !empty($_uri['modified_date'])) { $result = check_web_service_params($_uri); if ($result === 'valid') { @ini_set("max_execution_time", 999999999999.0); # unlimited @ini_set("memory_limit", "1000M"); # 1GB $records = $this->pbcore_model->get_assets_by_date_digitized($_uri['modified_date'], $_uri['digitized'], $_uri['page']); if (count($records) > 0) { $this->export_pbcore_premis->is_pbcore_export = TRUE; $this->export_pbcore_premis->make_collection_xml($records); echo $this->export_pbcore_premis->xml->asXML(); } else { $response = $this->export_pbcore_premis->xml_error('No record found.'); echo $response->asXML(); } } else { $response = $this->export_pbcore_premis->xml_error($result); echo $response->asXML(); } } else { $result = $this->export_pbcore_premis->xml_error('guid,digitized or modified_date. One of the parameter is required.'); echo $result->asXML(); } } }
/** * Process all pending csv exports. * * @return */ function csv_export_job() { set_time_limit(0); @ini_set("memory_limit", "1000M"); # 1GB @ini_set("max_execution_time", 999999999999.0); # 1GB $this->load->model('export_csv_job_model', 'csv_job'); $job = $this->csv_job->get_export_jobs('limited_csv'); if (count($job) > 0) { myLog('CSV Job Started.'); $filename = 'CSV_Export_' . time() . '.csv'; $folder_path = 'uploads/csv_exports/' . date('Y') . '/' . date('M') . '/'; $file_path = $folder_path . $filename; if (!is_dir($folder_path)) { mkdir($folder_path, 0777, TRUE); } $file_path = $folder_path . $filename; $fp = fopen($file_path, 'a'); $line = "GUID,Unique ID,Title,Format,Duration,Priority\n"; fputs($fp, $line); fclose($fp); myLog('Header File Saved.'); for ($i = 0; $i < $job->query_loop; $i++) { myLog('Query Loop ' . $i); $query = $job->export_query; $query .= ' LIMIT ' . $i * 100000 . ', 100000'; $records = $this->csv_job->get_csv_records($query); $fp = fopen($file_path, 'a'); $line = ''; foreach ($records as $value) { $line .= '"' . str_replace('"', '""', str_replace("\r", "", str_replace("\n", "", str_replace("\"", "\"\"", $value->GUID)))) . '",'; $line .= '="' . str_replace('"', '""', str_replace("\r", "", str_replace("\n", "", str_replace("\"", "\"\"", $value->unique_id)))) . '",'; $line .= '"' . str_replace('"', '""', str_replace("\r", "", str_replace("\n", "", str_replace("\"", "\"\"", $value->titles)))) . '",'; $line .= '"' . str_replace('"', '""', str_replace("\r", "", str_replace("\n", "", str_replace("\"", "\"\"", $value->format_name)))) . '",'; $line .= '="' . str_replace('"', '""', str_replace("\r", "", str_replace("\n", "", str_replace("\"", "\"\"", $value->projected_duration)))) . '",'; $line .= '"' . str_replace('"', '""', str_replace("\r", "", str_replace("\n", "", str_replace("\"", "\"\"", $value->status)))) . '"'; $line .= "\n"; } fputs($fp, $line); fclose($fp); $mem = memory_get_usage() / 1024; $mem = $mem / 1024; $mem = $mem / 1024; myLog($mem . ' GB'); myLog('Sleeping for 5 seconds'); sleep(3); } $url = site_url() . $file_path; $this->csv_job->update_job($job->id, array('status' => '1')); $user = $this->users->get_user_by_id($job->user_id)->row(); myLog('Sending Email to ' . $user->email); send_email($user->email, '*****@*****.**', 'Limited CSV Export', $url); exit_function(); } myLog('No Record available for csv export.'); exit_function(); }
/** * Make assets data to display in datatable for full view. * * @return json */ public function sort_full_table() { $column = array('Organization' => 'organization', 'Titles' => 'asset_title', 'AA_GUID' => 'guid_identifier', 'Local_ID' => 'local_identifier', 'Description' => 'description', 'Subjects' => 'asset_subject', 'Genre' => 'asset_genre', 'Assets_Date' => 'dates', 'Creator' => 'asset_creator_name', 'Contributor' => 'asset_contributor_name', 'Publisher' => 'asset_publisher_name', 'Coverage' => 'asset_coverage', 'Audience_Level' => 'asset_audience_level', 'Audience_Rating' => 'asset_audience_rating', 'Annotation' => 'asset_annotation', 'Rights' => 'asset_rights'); $this->session->unset_userdata('column'); $this->session->unset_userdata('jscolumn'); $this->session->unset_userdata('column_order'); $this->session->set_userdata('jscolumn', $this->input->get('iSortCol_0')); $this->session->set_userdata('column', $column[$this->column_order[$this->input->get('iSortCol_0')]['title']]); $this->session->set_userdata('column_order', $this->input->get('sSortDir_0')); $offset = isset($this->session->userdata['offset']) ? $this->session->userdata['offset'] : 0; $records = $this->sphinx->assets_listing($offset, 100, TRUE); $data['total'] = $records['total_count']; $record_ids = array_map(array($this, 'make_map_array'), $records['records']); $this->load->model('searchd_model', 'searchd'); $records = $this->searchd->get_assets($record_ids); // // $records = $records['records']; $data['count'] = count($records); $table_view = full_assets_datatable_view($records, $this->column_order); $dataTable = array("sEcho" => $this->input->get('sEcho') + 1, "iTotalRecords" => $data['count'], "iTotalDisplayRecords" => $data['count'], 'aaData' => $table_view); echo json_encode($dataTable); exit_function(); }
/** * Update the tracking information * * @return json */ public function update_tracking_info() { if (isAjax()) { $dates = $this->input->post(); foreach ($dates as $index => $value) { $tracking_id = explode('_', $index); $tracking_id = $tracking_id[count($tracking_id) - 1]; $media_date = date('Y-m-d', strtotime($value)); $this->tracking->update_record($tracking_id, array('media_received_date' => $media_date)); } echo json_encode(array('success' => TRUE)); exit_function(); } show_404(); }
/** * Export CSV file */ public function export_csv() { @ini_set("memory_limit", "3000M"); # 1GB @ini_set("max_execution_time", 999999999999.0); # 1GB $params = array('search' => ''); $records = $this->sphinx->instantiations_list($params); if ($records['total_count'] <= 10000) { $records = $this->instantiation->export_limited_csv(); if (count($records) > 0) { $this->load->library('excel'); $this->excel->getActiveSheetIndex(); $this->excel->getActiveSheet()->setTitle('Limited CSV'); $this->excel->getActiveSheet()->getColumnDimension('A')->setWidth(25); $this->excel->getActiveSheet()->getColumnDimension('B')->setWidth(25); $this->excel->getActiveSheet()->getColumnDimension('C')->setWidth(45); $this->excel->getActiveSheet()->getColumnDimension('D')->setWidth(10); $this->excel->getActiveSheet()->getColumnDimension('E')->setWidth(20); $this->excel->getActiveSheet()->getColumnDimension('F')->setWidth(25); $this->excel->getActiveSheet()->getStyle("A1:F1")->getFont()->setBold(true); $this->excel->getActiveSheet()->setCellValueExplicitByColumnAndRow(0, 1, 'GUID'); $this->excel->getActiveSheet()->setCellValueExplicitByColumnAndRow(1, 1, 'Unique ID'); $this->excel->getActiveSheet()->setCellValueExplicitByColumnAndRow(2, 1, 'Title'); $this->excel->getActiveSheet()->setCellValueExplicitByColumnAndRow(3, 1, 'Format'); $this->excel->getActiveSheet()->setCellValueExplicitByColumnAndRow(4, 1, 'Duration'); $this->excel->getActiveSheet()->setCellValueExplicitByColumnAndRow(5, 1, 'Priority'); $row = 2; foreach ($records as $value) { $col = 0; foreach ($value as $field) { $this->excel->getActiveSheet()->setCellValueExplicitByColumnAndRow($col, $row, $field); $col++; } $row++; } $filename = 'CSV_Export_' . time() . '.csv'; $folder_path = 'uploads/csv_exports/' . date('Y') . '/' . date('M') . '/'; $file_path = $folder_path . $filename; if (!is_dir($folder_path)) { mkdir($folder_path, 0777, TRUE); } $file_path = $folder_path . $filename; $objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5'); $objWriter->save($file_path); $this->excel->disconnectWorksheets(); unset($this->excel); echo json_encode(array('link' => 'true', 'msg' => site_url() . $file_path)); exit_function(); } else { echo json_encode(array('link' => 'false', 'msg' => 'No Record available for limited csv export')); exit_function(); } } else { $query = $this->instantiation->export_limited_csv(TRUE); $record = array('user_id' => $this->user_id, 'status' => 0, 'export_query' => $query, 'query_loop' => ceil($records['total_count'] / 100000)); $this->csv_job->insert_job($record); echo json_encode(array('link' => 'false', 'msg' => 'Email will be sent to you with the link of limited csv export.')); exit_function(); } }
/** * Generate standalone report with applied facets * and gives link to user to see the result. * */ public function generate_report() { $other = 0; $standalone = 0; $this->session->unset_userdata('stand_date_filter'); $session_keys = array('date_range', 'custom_search', 'organization', 'states', 'nomination', 'media_type', 'physical_format', 'digital_format', 'generation', 'digitized', 'migration_failed'); foreach ($session_keys as $value) { if (isset($this->session->userdata[$value])) { if ($value == 'digitized' && $this->session->userdata[$value] == 1) { $standalone = 1; } else { if (isset($this->session->userdata[$value]) && $this->session->userdata[$value] != '') { $other = 1; } } } } if ($standalone == 1 && $other == 0) { $data['filters'] = $this->input->post('date'); $data['user_id'] = $this->user_id; $data['report_type'] = 'standalone'; if (!empty($data['filters'])) { $this->session->set_userdata('stand_date_filter', $data['filters']); } $records = $this->sphinx->standalone_report(); if (count($records['records']) > 0) { $report_id = $this->report_model->insert_report($data); $url = site_url() . "reports/standalone/" . base64_encode($report_id); echo json_encode(array('msg' => "<a href='{$url}' target='_blank'>{$url}</a>")); } else { echo json_encode(array('msg' => "No record available against " . $data['filters'] . '.')); } } else { echo json_encode(array('msg' => "Please apply Digitized filter from facet sidebar for standalone report.")); } exit_function(); }