public function action_fill() { $id = Arr::get($_GET, 'id'); if ($id) { $filters = array('_id' => new MongoId($id)); if (!Group::current('show_all_jobs')) { $filters['company'] = User::current('company_id'); } $form_data = Database_Mongo::collection('forms-data')->findOne($filters); $form_id = $form_data['form_id']; } else { $data = explode('/', Arr::get($_GET, 'form', '')); $form_id = $data[0]; $form_data = array(); } $form = Database_Mongo::collection('forms')->findOne(array('_id' => new MongoId($form_id))); if (!$form) { throw new HTTP_Exception_404('Not found'); } if (!$form_data) { $form_data['form_id'] = $form_id; $form_data['data'] = array(); foreach ($form['data'] as $key => $table) { if (is_array($table) && Arr::get($table, 'type') == 'table') { foreach ($table['data'] as $row => $cells) { foreach ($cells as $cell => $input) { if (Arr::get($input, 'name')) { $form_data['data'][$input['name']] = ''; } } } } } } switch ($form['type']) { case Form::FORM_TYPE_COMMON: break; case Form::FORM_TYPE_TICKET: if (isset($form_data['job'])) { $job_id = $form_data['job']; } else { $job_id = $data[1]; $form_data['job'] = $job_id; } $job = Database_Mongo::collection('jobs')->findOne(array('_id' => strval($job_id))); if (!$job) { throw new HTTP_Exception_404('Not found'); } if (!Group::current('show_all_jobs') && !in_array(User::current('company_id'), array_merge(Arr::get($job, 'companies', array()), Arr::get($job, 'ex', array())))) { throw new HTTP_Exception_404('Not found'); } foreach ($form['data'] as $key => $table) { if (is_array($table) && Arr::get($table, 'type') == 'table') { foreach ($table['data'] as $row => $cells) { foreach ($cells as $cell => $input) { switch (Arr::get($input, 'type')) { case 'ticket': $form['data'][$key]['data'][$row][$cell]['type'] = 'label'; $form['data'][$key]['data'][$row][$cell]['placeholder'] = Arr::get($input, 'value') ? Columns::output(Arr::path($job, 'data.' . $input['value']), Columns::get_type($input['value'])) : $job['_id']; $form['data'][$key]['data'][$row][$cell]['destination'] = Arr::get($input, 'destination'); unset($form['data'][$key]['data'][$row][$cell]['value']); break; case 'timestamp': $form['data'][$key]['data'][$row][$cell] = array('type' => 'timestamp', 'placeholder' => Arr::get($form_data, 'last_update') ? date('d-m-Y H:i', $form_data['last_update']) : '', 'destination' => Arr::get($input, 'destination')); break; case 'revision': $form['data'][$key]['data'][$row][$cell] = array('type' => 'revision', 'placeholder' => Arr::get($form_data, 'revision', 1), 'destination' => Arr::get($input, 'destination')); break; } } } } } break; } if (isset($_GET['load']) || isset($_GET['print']) || $_POST) { header('Content-type: application/json'); if (isset($form_data['job'])) { $job = Database_Mongo::collection('jobs')->findOne(array('_id' => is_array($form_data['job']) ? array('$in' => $form_data['job']) : $form_data['job'])); } if ($_POST || isset($_GET['print'])) { if (isset($_GET['print'])) { $columns = DB::select('id')->from('report_columns')->where('report_id', '=', Arr::get($form, 'report'))->execute()->as_array('id', 'id'); $report = array(); $colors = array(); $update = array(); $hide = array(); foreach ($form['data'] as $key => $table) { if (is_array($table) && Arr::get($table, 'type') == 'table') { if (Arr::get($table, 'data-related-option') && Arr::get($table, 'data-related-value') != Arr::get($form_data['data'], $table['data-related-option'])) { $hide[] = $key; } else { foreach ($table['data'] as $row => $cells) { foreach ($cells as $cell => $input) { switch (Arr::get($input, 'type')) { case 'revision': $form['data'][$key]['data'][$row][$cell]['placeholder'] = $input['placeholder'] = Arr::get($form_data, 'revision', 1); break; case 'timestamp': $form['data'][$key]['data'][$row][$cell]['placeholder'] = $input['placeholder'] = Arr::get($form_data, 'last_update') ? date('d-m-Y H:i', $form_data['last_update']) : ''; break; } if (Arr::get($input, 'name')) { $form['data'][$key]['data'][$row][$cell]['value'] = $input['value'] = Arr::path($form_data, array('data', $input['name']), ''); } if (Arr::get($input, 'destination') && isset($columns[$input['destination']])) { if (isset($input['colors'])) { try { $list = array_combine(explode(',', $input['options']), explode(',', $input['colors'])); $color = Arr::get($list, $input['value']); } catch (Exception $e) { $color = false; } if ($color) { $colors[$input['destination']] = $color; } } $report[$input['destination']] = Arr::get($input, in_array(Arr::get($input, 'type', ''), array('text', 'number', 'float', 'date', 'options')) ? 'value' : 'placeholder'); } if (Arr::get($input, 'bindValue')) { $bind = explode(',', $input['bindValue']); foreach ($bind as $target) { $update[$target] = array('value' => Arr::get($input, in_array(Arr::get($input, 'type', ''), array('text', 'number', 'float', 'date', 'options')) ? 'value' : 'placeholder'), 'type' => 'replace'); } } } } } } } foreach ($hide as $key) { unset($form['data'][$key]); } $view = View::factory('Forms/PDF')->bind('name', $form['name'])->bind('form', $form['data'])->set('attachments', Arr::get($form_data, 'attachments', array())); require_once APPPATH . 'mpdf/mpdf.php'; $pdf = new mPDF('UTF-8', 'A4'); $pdf->ignore_invalid_utf8 = true; $pdf->shrink_tables_to_fit = 1; $pdf->keep_table_proportions = true; $pdf->WriteHTML($view); $content = $pdf->Output('', 'S'); $name = trim(preg_replace('/-{2,}/', '-', preg_replace('/[^a-z0-9]/i', '-', $form['name'])), '-'); switch ($form['type']) { case Form::FORM_TYPE_COMMON: $jobs = array(0); break; case Form::FORM_TYPE_TICKET: $jobs = array($job['_id']); break; } $company = DB::select('name')->from('companies')->where('id', '=', $form_data['company'])->execute()->get('name'); $uploaded = time(); $submissions = array(); $submission = array('user_id' => User::current('id'), 'active' => 1, 'update_time' => $uploaded); foreach ($jobs as $job) { if ($job) { $job = Database_Mongo::collection('jobs')->findOne(array('_id' => $job), array('data' => 1)); $new = array(); $archive = array(); foreach ($update as $key => $value) { if ($value['type'] == 'append') { switch (Columns::get_type($key)) { case 'int': case 'number': case 'float': $value = Arr::path($job, 'data.' . $key, 0) + $value['value']; break; default: $value = Arr::path($job, 'data.' . $key, '') . "\n" . $value['value']; break; } } else { $value = $value['value']; } if ($value) { $value = Columns::parse($value, Columns::get_type($key)); } if (Group::current('allow_assign') || Columns::get_direct($key)) { if ($value) { $new['$set']['data.' . $key] = $value; } else { $new['$unset']['data.' . $key] = 1; } if (!Group::current('allow_assign')) { $submission['job_key'] = $job['_id']; $submission['key'] = 'data.' . $key; $submission['value'] = $value; $submission['active'] = -1; $submission['process_time'] = $uploaded; Database_Mongo::collection('submissions')->insert($submission); unset($submission['process_time']); unset($submission['_id']); } $archive['data'][$key] = array('old_value' => Arr::path($job, 'data.' . $key, ''), 'new_value' => $value); } else { $new['$set']['status'] = Enums::STATUS_PENDING; $submissions[$job['_id']][$key] = $value; } } if ($new) { $new['$set']['last_update'] = $uploaded; Database_Mongo::collection('jobs')->update(array('_id' => $job['_id']), $new); if ($archive) { $archive['fields'] = array_keys($archive['data']); $archive['job_key'] = $job['_id']; $archive['user_id'] = User::current('id'); $archive['update_time'] = $uploaded; $archive['update_type'] = 2; $archive['filename'] = 'MANUAL'; Database_Mongo::collection('archive')->insert($archive); } } } $filename = $name . ' (' . $company . ') -' . date('dmY-His') . '.pdf'; $data = array('filename' => $filename, 'mime' => 'application/pdf', 'uploaded' => $uploaded, 'user_id' => $form_data['user_id'], 'job_id' => $job ? $job['_id'] : 0, 'folder' => 'Reports', 'fda_id' => $job ? Arr::path($job, 'data.14') : 'Unattached', 'address' => $job ? trim(preg_replace('/-{2,}/', '-', preg_replace('/[^0-9a-z\\-]/i', '-', Arr::path($job, 'data.8'))), '-') : 'Unattached', 'title' => ''); Database::instance()->begin(); $result = DB::insert('attachments', array_keys($data))->values(array_values($data))->execute(); $image_id = Arr::get($result, 0); if ($image_id && file_put_contents(DOCROOT . 'storage/' . $image_id, $content)) { unset($data['mime']); $data = array('filename' => 'Reports / ' . ($job ? Arr::path($job, 'data.14') : 'Unattached') . ' / ' . ($job ? $data['address'] : 'Unattached') . ' / ' . $data['filename'], 'uploaded' => $uploaded, 'user_id' => User::current('id'), 'job_id' => $job ? $job['_id'] : 0, 'action' => 1); DB::insert('upload_log', array_keys($data))->values(array_values($data))->execute(); Database::instance()->commit(); Database_Mongo::collection('forms-data')->remove(array('_id' => new MongoId($id))); if ($report) { $data = $report; $report = array('report_id' => intval(Arr::get($form, 'report')), 'user_id' => $form_data['user_id'], 'company' => $form_data['company'], 'attachment_id' => $image_id, 'attachment' => $filename, 'uploaded' => $uploaded, 'colors' => $colors); if (Arr::get($form_data, 'attachments')) { $report['attachments'] = $form_data['attachments']; } if (isset($form_data['geo'])) { $report['geo'] = $form_data['geo']; } $columns = DB::select('id', 'type')->from('report_columns')->where('report_id', '=', $report['report_id'])->execute()->as_array('id', 'type'); foreach ($columns as $key => $value) { $report[$key] = Arr::get($data, $key) ? Columns::parse($data[$key], $value) : ''; } Database_Mongo::collection('reports')->insert($report); } } else { Messages::save('Error occurred during report processing... Please try again later'); } } foreach ($submissions as $job_key => $values) { foreach ($values as $key => $value) { $submission['job_key'] = $job_key; $submission['key'] = 'data.' . $key; $submission['value'] = $value; $submission['active'] = 1; Database_Mongo::collection('submissions')->insert($submission); unset($submission['_id']); } } $target = 'attachments'; } else { $target = 'forms'; $fl = false; foreach ($form_data['data'] as $key => $value) { if (Arr::get($_POST, $key) != $value) { $form_data['data'][$key] = Arr::get($_POST, $key); $fl = true; } } if ($fl) { $form_data['last_update'] = time(); if (Arr::get($form, 'geo')) { $form_data['geo'] = Arr::get($_POST, 'geo'); } } if ($id) { if ($fl) { $form_data['revision']++; } Database_Mongo::collection('forms-data')->update(array('_id' => new MongoId($id)), $form_data); } else { $form_data['created'] = time(); $form_data['user_id'] = User::current('id'); $form_data['company'] = User::current('company_id'); $form_data['revision'] = 1; $form_data['last_update'] = time(); Database_Mongo::collection('forms-data')->insert($form_data); $id = strval($form_data['_id']); } } header('Content-type: application/json'); switch ($form['type']) { case Form::FORM_TYPE_TICKET: $url = URL::base() . 'search/view/' . $form_data['job'] . '#' . $target; break; case Form::FORM_TYPE_COMMON: $url = URL::base() . 'form/unattached'; break; } die(json_encode(array('success' => true, 'id' => $id, 'url' => $url))); } foreach ($form['data'] as $key => $table) { if (is_array($table) && Arr::get($table, 'type') == 'table') { foreach ($table['data'] as $row => $cells) { foreach ($cells as $cell => $input) { if (Arr::get($input, 'name')) { $form['data'][$key]['data'][$row][$cell]['value'] = Arr::get($form_data['data'], $input['name']); } } } } } die(json_encode(array('form' => $form['data'], 'attachments' => Arr::get($form_data, 'attachments')))); } $view = View::factory('Forms/Form')->set('form_id', $form_id)->set('id', $id)->set('allow_geo', Arr::get($form, 'geo'))->set('allow_attachment', Arr::get($form, 'attachment'))->set('name', $form['name']); $this->response->body($view); }
public function action_index() { $start = Arr::get($_GET, 'start') ? strtotime($_GET['start']) : strtotime('this week', strtotime('this week') > time() ? strtotime('yesterday') : time()); $end = Arr::get($_GET, 'end') ? strtotime($_GET['end']) + 86399 : time(); $query = array('update_time' => array('$gt' => intval($start), '$lt' => intval($end))); if (Arr::get($_GET, 'app-start')) { $query['process_time']['$gt'] = strtotime($_GET['app-start']); } if (Arr::get($_GET, 'app-end')) { $query['process_time']['$lt'] = strtotime($_GET['app-end']) + 86399; } if (Group::current('allow_assign')) { $companies = DB::select('id', 'name')->from('companies')->order_by('name', 'asc')->execute()->as_array('id', 'name'); } if (!Group::current('allow_assign') || Arr::get($_GET, 'company')) { $query['user_id'] = array('$in' => DB::select('id')->from('users')->where('company_id', '=', Group::current('allow_assign') ? $_GET['company'] : User::current('company_id'))->execute()->as_array(NULL, 'id')); } $jobs = array(); if (Arr::get($_GET, 'finished')) { $jobs['data.245'] = $_GET['finished']; } if (Arr::get($_GET, 'ticket')) { $tickets = explode(',', $_GET['ticket']); $q = array(); foreach ($tickets as $ticket) { $ticket = preg_replace('/[^a-z0-9]/i', '', strval($ticket)); if (!$ticket) { continue; } if (preg_match('/^T1W[0-9]{12}$/', $ticket)) { $q[] = $ticket; } else { $q[] = new MongoRegex('/.*' . $ticket . '.*/i'); } } if (count($q) > 1) { $jobs['_id'] = array('$in' => $q); } elseif ($q) { $jobs['_id'] = $q[0]; } } if (Arr::get($_GET, 'fsa')) { $values = is_array($_GET['fsa']) ? $_GET['fsa'] : explode(',', $_GET['fsa']); $jobs['data.12'] = count($values) > 1 ? array('$in' => array_values($values)) : current($values); } if (Arr::get($_GET, 'fsam')) { $values = is_array($_GET['fsam']) ? $_GET['fsam'] : explode(',', $_GET['fsam']); $jobs['data.13'] = count($values) > 1 ? array('$in' => array_values($values)) : current($values); } if (Arr::get($_GET, 'fda')) { $values = is_array($_GET['fda']) ? $_GET['fda'] : explode(',', $_GET['fda']); $jobs['data.14'] = count($values) > 1 ? array('$in' => array_values($values)) : current($values); } if (Arr::get($_GET, 'address')) { $jobs['data.8'] = new MongoRegex('/.*' . strval($_GET['address']) . '.*/mi'); } if ($jobs) { if (count($jobs) == 1 && isset($jobs['_id'])) { $query['job_key'] = $jobs['_id']; } else { $query['job_key'] = array('$in' => Database_Mongo::collection('jobs')->distinct('_id', $jobs)); } } $sort = array('job_key' => 1); if (!Arr::get($_GET, 'sort')) { $_GET['sort'] = array('-submission'); } foreach ($_GET['sort'] as $s) { $dir = substr($s, 0, 1) == '-' ? -1 : 1; $s = substr($s, 1); switch ($s) { case 'submission': $sort['update_time'] = $dir; break; case 'approval': $sort['process_time'] = $dir; break; } } $result = Database_Mongo::collection('submissions')->find($query)->sort($sort); $submissions = array(); $users = array(); foreach ($result as $submission) { $submissions[$submission['job_key']][] = $submission; $users[$submission['user_id']] = 1; } if ($users) { User::get(array_keys($users)); } if (isset($_GET['export'])) { header('Content-type: text/csv'); header('Content-disposition: filename="Submissions.' . date('Ymd', $start) . '-' . date('Ymd', $end) . '.' . date('YmdHi', time()) . '.csv"'); $file = tmpfile(); $headers = array('Tickets ID', 'FDA ID', 'LOC ID', 'Address', 'Submission Date', 'Approval Date', 'User'); if (Group::current('allow_assign')) { $headers[] = 'Company'; } $headers[] = 'Column'; $headers[] = 'Value'; fputcsv($file, $headers); $result = Database_Mongo::collection('jobs')->find(array('_id' => array('$in' => array_keys($submissions))), array('data.8' => 1, 'data.9' => 1, 'data.14' => 1)); $jobs = array(); foreach ($result as $job) { $jobs[$job['_id']] = array('a' => Arr::path($job, 'data.8', ''), 'f' => Arr::path($job, 'data.14', ''), 'l' => Arr::path($job, 'data.9', '')); } foreach ($submissions as $job => $list) { foreach ($list as $submission) { $key = substr($submission['key'], 5); $data = array($job, Arr::path($jobs, array($job, 'f')), Arr::path($jobs, array($job, 'l')), Arr::path($jobs, array($job, 'a')), date('d-m-Y H:i', $submission['update_time']), Arr::get($submission, 'process_time') ? date('d-m-Y H:i', $submission['process_time']) : '', User::get($submission['user_id'], 'login')); if (Group::current('allow_assign')) { $data[] = Arr::get($companies, User::get($submission['user_id'], 'company_id'), 'Unknown'); } $data[] = Columns::get_name($key); $data[] = Columns::output($submission['value'], Columns::get_type($key), true); fputcsv($file, $data); } } fseek($file, 0); fpassthru($file); fclose($file); die; } elseif (isset($_GET['export2'])) { //header('Content-type: text/plain'); header('Content-type: text/csv'); header('Content-disposition: filename="Submissions.' . date('Ymd', $start) . '-' . date('Ymd', $end) . '.' . date('YmdHi', time()) . '.csv"'); $result = array(); $columns = array(); foreach ($submissions as $job => $list) { foreach ($list as $submission) { $key = substr($submission['key'], 5); $result[$job][$submission['update_time']][$submission['user_id']][$key] = $submission['value']; $columns[$key] = Columns::get_name($key); } } $submissions = $result; ksort($columns); $headers = array('Tickets ID', 'FDA ID', 'LOC ID', 'Address', 'Submission Date', 'User'); if (Group::current('allow_assign')) { $headers[] = 'Company'; } /*$columns = Columns::get_visible();*/ foreach ($columns as $column) { $headers[] = $column; } $columns = array_keys($columns); $result = Database_Mongo::collection('jobs')->find(array('_id' => array('$in' => array_keys($submissions))), array('data.8' => 1, 'data.9' => 1, 'data.14' => 1)); $jobs = array(); foreach ($result as $job) { $jobs[$job['_id']] = array('f' => Arr::path($job, 'data.14', ''), 'l' => Arr::path($job, 'data.9', ''), 'a' => Arr::path($job, 'data.8', '')); } $file = tmpfile(); fputcsv($file, $headers); foreach ($submissions as $job => $list) { foreach ($list as $time => $values) { foreach ($values as $user => $submission) { $row = array($job, Arr::path($jobs, $job . '.f'), Arr::path($jobs, $job . '.l'), Arr::path($jobs, $job . '.a'), date('d-m-Y H:i', $time), User::get($user, 'login')); if (Group::current('allow_assign')) { $row[] = Arr::get($companies, User::get($user, 'company_id')); } foreach ($columns as $column) { $row[] = Columns::output(Arr::get($submission, $column, ''), Columns::get_type($column), true); } fputcsv($file, $row); } } } fseek($file, 0); fpassthru($file); fclose($file); //print_r($result); die; } elseif (isset($_GET['export3'])) { //header('Content-type: text/plain'); header('Content-type: text/csv'); header('Content-disposition: filename="Submissions.' . date('Ymd', $start) . '-' . date('Ymd', $end) . '.' . date('YmdHi', time()) . '.csv"'); $result = array(); foreach ($submissions as $job => $list) { foreach ($list as $submission) { $key = substr($submission['key'], 5); $result[$job][$submission['update_time']][$submission['user_id']][$key] = $submission['value']; } } $submissions = $result; $headers = array('Tickets ID', 'FDA ID', 'LOC ID', 'Address', 'Submission Date', 'User'); if (Group::current('allow_assign')) { $headers[] = 'Company'; } $columns = Columns::get_visible(); foreach ($columns as $column) { $headers[] = $column; } $columns = array_keys($columns); $result = Database_Mongo::collection('jobs')->find(array('_id' => array('$in' => array_keys($submissions))), array('data.8' => 1, 'data.9' => 1, 'data.14' => 1)); $jobs = array(); foreach ($result as $job) { $jobs[$job['_id']] = array('f' => Arr::path($job, 'data.14', ''), 'l' => Arr::path($job, 'data.9', ''), 'a' => Arr::path($job, 'data.8', '')); } $file = tmpfile(); fputcsv($file, $headers); foreach ($submissions as $job => $list) { foreach ($list as $time => $values) { foreach ($values as $user => $submission) { $row = array($job, Arr::path($jobs, $job . '.f'), Arr::path($jobs, $job . '.l'), Arr::path($jobs, $job . '.a'), date('d-m-Y H:i', $time), User::get($user, 'login')); if (Group::current('allow_assign')) { $row[] = Arr::get($companies, User::get($user, 'company_id')); } foreach ($columns as $column) { $row[] = Arr::get($submission, $column) ? Columns::output($submission[$column], Columns::get_type($column), true) : ''; } fputcsv($file, $row); } } } fseek($file, 0); fpassthru($file); fclose($file); //print_r($result); die; } $result = Database_Mongo::collection('jobs')->find(array('_id' => array('$in' => array_keys($submissions))), array('data.8' => 1, 'data.9' => 1, 'data.14' => 1)); $jobs = array(); foreach ($result as $job) { $jobs[$job['_id']] = array('f' => Arr::path($job, 'data.14', ''), 'l' => Arr::path($job, 'data.9', ''), 'a' => Arr::path($job, 'data.8', '')); } $view = View::factory("Reports/Submissions")->bind('companies', $companies)->bind('submissions', $submissions)->bind('jobs', $jobs); $this->response->body($view); }
public function action_export() { $id = $this->request->param('id'); if ($id == 'all') { ini_set('memory_limit', '4G'); } $result = $this->get_results($id == 'all'); $reports = array(); foreach (Columns::get_static() as $column => $value) { $reports[$column] = Columns::get_name($column); } $file = tmpfile(); $actions = array('1' => 'Created', '2' => 'Updated', '3' => 'Removed'); $data = array('Ticket ID', 'Date', 'Action', 'File name'); foreach ($reports as $id => $name) { $data[] = $name; } $data[] = "Column name"; $data[] = "Old value"; $data[] = "New value"; fputcsv($file, $data); foreach ($result as $ticket) { $ticket['update_time'] = date('d-m-Y H:i', $ticket['update_time']); $ticket['type'] = Arr::get($actions, $ticket['update_type'], 'Unknown'); $data = array($ticket['job_key'], $ticket['update_time'], $ticket['type'], $ticket['filename']); foreach ($reports as $id => $name) { $data[] = Columns::output(Arr::path($ticket, 'static.' . $id), Columns::get_type($id), true); } if ($ticket['update_type'] == 2) { if ($ticket['data']) { $base = $data; foreach ($ticket['data'] as $key => $value) { $data = $base; $date = Columns::get_type($key) == 'date'; $data[] = Columns::get_name($key); $data[] = $date && $value['old_value'] ? date('d-m-Y H:i', $value['old_value']) : $value['old_value']; $data[] = $date && $value['new_value'] ? date('d-m-Y H:i', $value['new_value']) : $value['new_value']; fputcsv($file, $data); } } else { $data[] = "Non-relevant"; fputcsv($file, $data); } } else { $data[] = "N/A"; fputcsv($file, $data); } } rewind($file); header('Content-type: text/csv'); header('Content-disposition: filename=Export.csv'); fpassthru($file); fclose($file); die; }
<th class="sortable" data-id="submission">Submission date</th> <th class="sortable" data-id="approval">Approval date</th> <th>User</th> <?php if (Group::current('allow_assign')):?><th>Company</th><?php endif;?> <th>Column</th> <th>Value</th> </tr> <?php foreach ($submissions as $job => $list):?> <tr class="text-center"> <th colspan="<?=(Group::current('allow_assign')) ? 6 : 5?>"> <a href="<?=URL::base()?>search/view/<?=$job?>"><?=$job?>, <?=Arr::path($jobs, array($job, 'l'))?>, <?=Arr::path($jobs, array($job, 'f'))?>, <?=Arr::path($jobs, array($job, 'a'))?></a> </th> </tr> <?php foreach ($list as $submission): $key = substr($submission['key'], 5); $status = Arr::get($submission, 'active', 0);?> <tr class="text-center <?=$status > 0 ? 'yellow' : ($status < 0 ? 'lgreen' : 'rose')?>"> <td><?=date('d-m-Y H:i', $submission['update_time'])?></td> <td><?=isset($submission['process_time']) ? date('d-m-Y H:i', $submission['process_time']) : ''?></td> <td><?=User::get($submission['user_id'], 'login')?></td> <?php if (Group::current('allow_assign')):?><td><?=Arr::get($companies, User::get($submission['user_id'], 'company_id'), 'Unknown')?></td><?php endif;?> <td><?=Columns::get_name($key)?></td> <td class="<?=strlen(Columns::output($submission['value'], Columns::get_type($key))) > 2 ? 'shorten' : ''?>"><?=Columns::output($submission['value'], Columns::get_type($key))?></td> </tr> <?php endforeach;?> <?php endforeach;?> </table> <div class="upload-buttons text-right"> <a href="?export&company=<?=Arr::get($_GET, 'company')?>&start=<?=Arr::get($_GET, 'start', date('d-m-Y', $week))?>&end=<?=Arr::get($_GET, 'end', date('d-m-Y'))?>" class="btn btn-info"><span class="glyphicon glyphicon-export"></span> Export</a> <a href="?export2&company=<?=Arr::get($_GET, 'company')?>&start=<?=Arr::get($_GET, 'start', date('d-m-Y', $week))?>&end=<?=Arr::get($_GET, 'end', date('d-m-Y'))?>" class="btn btn-primary"><span class="glyphicon glyphicon-export"></span> Export grouped</a> <a href="?export3&company=<?=Arr::get($_GET, 'company')?>&start=<?=Arr::get($_GET, 'start', date('d-m-Y', $week))?>&end=<?=Arr::get($_GET, 'end', date('d-m-Y'))?>" class="btn btn-warning"><span class="glyphicon glyphicon-export"></span> Export all columns</a> </div>
</tr> <?php foreach ($list as $submission): $key = substr($submission['key'], 5); $type = Columns::get_type($key); $discr = Group::current('allow_assign') && Arr::path($jobs, $job . '.' . $submission['key']) != $submission['value']; $rate = Arr::path($rates, array(User::get($submission['user_id'], 'company_id'), $region, $key), Arr::path($rates, array(User::get($submission['user_id'], 'company_id'), 0, $key), 0));?> <tr class="submission text-center <?=$discr ? 'rose' : (Arr::get($_GET, 'discrepancy') ? 'hidden ' : '') . (Arr::get($submission, 'financial_time') ? 'lgreen' : 'yellow')?>" data-id="<?=$job?>"> <td><?=date('d-m-Y H:i', $submission['update_time'])?></td> <td><?=Arr::get($submission, 'process_time') ? date('d-m-Y H:i', $submission['process_time']) : ''?></td> <td class="time"><?=Arr::get($submission, 'financial_time') ? date('d-m-Y H:i', $submission['financial_time']) : ''?></td> <td><?=User::get($submission['user_id'], 'login')?></td> <?php if (Group::current('allow_assign')):?><td><?=Arr::get($companies, User::get($submission['user_id'], 'company_id'), 'Unknown')?></td><?php endif;?> <td><?=Columns::get_name($key)?></td> <td <?=strlen(Columns::output($submission['value'], $type)) > 100 ? 'class="shorten"' : ''?>><?=Columns::output($submission['value'], $type);?></td> <?php if (Group::current('allow_assign')):?><td><?=Arr::path($jobs, $job . '.' . $submission['key']) ? Columns::output($jobs[$job]['data'][$key], $type) : ''?></td><?php endif;?> <td class="paid"><?=Arr::get($submission, 'paid')?></td> <td><?=floatval(Arr::get($columns, $key))?></td> <td class="rate"><?=Arr::get($submission, 'rate') ? number_format($submission['rate'], 2) : $rate?></td> <?php if (Group::current('allow_assign')):?> <td> <?php if (!$submission['financial_time'] && $rate):?> <button type="button" data-rate="<?=$rate?>" data-id="<?=$submission['_id']?>" data-value="<?=min(floatval(Arr::get($columns, $key)), floatval($submission['value']) ? : 1)?>" data-max="<?=floatval(Arr::get($columns, $key))?>" class="btn btn-success approve-financial">Approve</button> <?php elseif ($submission['financial_time']):?> <button type="button" data-rate="<?=$rate?>" data-id="<?=$submission['_id']?>" data-value="<?=min(floatval(Arr::get($columns, $key)), floatval($submission['value']) ? : 1)?>" data-max="<?=floatval(Arr::get($columns, $key))?>" class="btn btn-warning unapprove-financial">Unapprove</button> <?php else: echo ' '; endif;?> </td> <?php endif;?> </tr> <?php endforeach;?>
public function action_index() { if (!Group::current('allow_reports')) { throw new HTTP_Exception_403('Forbidden'); } $regions = DB::select('id', 'name')->from('regions')->execute()->as_array('id', 'name'); $groups = DB::select('id', 'name')->from('groups')->execute()->as_array('id', 'name'); $form = new Form(); $form->add('region', 'Region', Form::SELECT, array('' => 'Please, select region') + $regions, array('not_empty')); if (isset($_POST['group']) && isset($_POST['csv'])) { if (isset($_POST['job'])) { $query = array('_id' => array('$in' => array_keys($_POST['job']))); $region = array('name' => 'PARTIAL'); } else { if (!Arr::get($_POST, 'region')) { throw new HTTP_Exception_404('Not found'); } $region = DB::select('id', 'name')->from('regions')->where('id', '=', $_POST['region'])->execute()->current(); $query = array('region' => $region['id']); } $jobs = Database_Mongo::collection('jobs')->find($query); $columns = array(); $csv = $_POST['csv']; if ($_POST['group']) { if (Group::get($_POST['group'], 'is_admin')) { $result = DB::select('id')->from('job_columns')->execute()->as_array(NULL, 'id'); } else { $result = DB::select('column_id')->from('group_columns')->where('group_id', '=', $_POST['group'])->and_where('permissions', '>', 0)->execute()->as_array(NULL, 'column_id'); } if ($csv != 'none') { foreach ($result as $column) { if ($csv == 'all' || !($csv == 'csv' xor Columns::get_csv($column))) { $columns[$column] = Columns::get_name($column); } } } } else { foreach (Arr::get($_POST, 'columns', array()) as $column => $value) { $columns[$column] = Columns::get_name($column); } } header("Content-type: text/csv"); header('Content-disposition: filename="' . date('Ymd') . '_EXEL_' . $region['name'] . '_EOD.csv"'); $file = tmpfile(); fputcsv($file, array(0 => 'Ticket Of Work') + $columns); while ($job = $jobs->next()) { $data[0] = $job['_id']; $i = 1; foreach ($columns as $key => $value) { $data[$i++] = iconv("CP1251", 'CP1251//ignore', Columns::output(Arr::get($job['data'], $key, ''), Columns::get_type($key), true)); } fputcsv($file, $data); } rewind($file); fpassthru($file); fclose($file); die; } $view = View::factory('Jobs/Export')->bind('regions', $regions)->bind('groups', $groups); $this->response->body($view); }
public function action_index() { if (!Group::current('allow_assign')) { throw new HTTP_Exception_403('Forbidden'); } header('Content-type: application/json'); $action = $this->request->param('id'); $result = array(); $columns = DB::select('id')->from('job_columns')->where('editable', '=', 1)->execute()->as_array('id', 'id'); switch ($action) { case 'get': $data = array(); $result['columns'] = array(); foreach ($columns as $column) { $value = array('id' => intval($column), 'name' => Columns::get_name($column)); $type = Columns::get_type($column); if (substr($type, 0, 4) == 'enum') { $id = substr($type, 5); $type = Enums::is_multi($id) ? 'multi' : 'list'; $value['values'] = array_values(Enums::get_values($id)); } $value['type'] = $type ?: 'string'; $result['columns'][] = $value; $data[] = 'data.' . $column; } $ids = explode(',', strval(Arr::get($_GET, 'id', ''))); $values = array(); if ($ids) { $query = array('_id' => array('$in' => $ids)); if (!Group::current('show_all_jobs')) { $query['companies'] = intval(User::current('company_id')); } $jobs = Database_Mongo::collection('jobs')->find($query, $data); foreach ($jobs as $job) { foreach ($job['data'] as $key => $value) { $job['data'][$key] = Columns::output($value, Columns::get_type($key), true); } $job['id'] = $job['_id']; unset($job['_id']); $values[] = $job; } } $result['jobs'] = $values; break; case 'set': if (User::current('login') !== Arr::get($_POST, 'username')) { die('Wrong username! Please, check it and submit data again.'); } $data = Arr::get($_POST, 'jobs'); $values = array(); foreach ($data as $job) { $id = strval(Arr::get($job, 'id', '')); foreach (Arr::get($job, 'data') as $key => $value) { if (isset($columns[$key])) { $values[$id][$key] = strval($value); } } } $query = array('_id' => array('$in' => array_keys($values))); if (!Group::current('show_all_jobs')) { $query['companies'] = intval(User::current('company_id')); } $data = array(); foreach ($columns as $column) { $data['data.' . $column] = 1; } $count = 0; $jobs = Database_Mongo::collection('jobs')->find($query, $data); foreach ($jobs as $job) { if (isset($values[$job['_id']])) { $id = $job['_id']; $new = array(); $archive = array(); foreach ($values[$id] as $key => $value) { $value = $value ? Columns::parse($value, Columns::get_type($key)) : ''; $old = Arr::path($job, 'data.' . $key); if (($value || $old) && $value != $old) { if ($value) { $new['$set']['data.' . $key] = $value; } else { $new['$unset']['data.' . $key] = 1; } $archive['data'][$key] = array('old_value' => $old, 'new_value' => $value); } } if ($new) { $new['$set']['last_update'] = time(); Database_Mongo::collection('jobs')->update(array('_id' => $id), $new); $archive['fields'] = array_keys($archive['data']); $archive['job_key'] = $id; $archive['user_id'] = User::current('id'); $archive['update_time'] = time(); $archive['update_type'] = 2; $archive['filename'] = 'MANUAL'; Database_Mongo::collection('archive')->insert($archive); $count++; } } } $result = array('success' => true, 'count' => $count); break; } die(json_encode($result)); }
public function action_index() { $action = $this->request->param('id'); $ids = array_keys(Arr::get($_POST, 'job', array())); if (!$ids) { throw new HTTP_Exception_404('Not found'); } $regs = DB::select('region_id')->from('user_regions')->where('user_id', '=', User::current('id'))->execute()->as_array('region_id', 'region_id'); $query = array(); if ($regs) { $query['region'] = array('$in' => array_values($regs)); } if (!Group::current('show_all_jobs')) { $query['$or'] = array(array('ex' => intval(User::current('company_id'))), array('companies' => intval(User::current('company_id')))); } $query['_id'] = array('$in' => $ids); $jobs = Database_Mongo::collection('jobs')->find($query); $static = array_flip(explode(',', Group::current('columns'))); $header = array('Ticket ID'); $types = DB::select('id', 'name')->from('job_types')->execute()->as_array('id', 'name'); $companies = DB::select('id', 'name')->from('companies')->execute()->as_array('id', 'name'); if ($action == 'excel') { $result = DB::select()->from('attachments')->where('job_id', 'IN', $ids)->and_where('uploaded', '>', 0)->and_where('folder', '<>', 'Signatures')->execute()->as_array(); $attachments = array(); $attachments_list = array(); foreach ($result as $row) { $attachments[$row['job_id']] = Arr::get($attachments, $row['job_id'], 0) + 1; if (preg_match('/^image\\/.*$/i', $row['mime'])) { $attachments_list[$row['job_id']][] = $row['id']; } } } elseif ($ids && $static['attachments']) { $attachments = DB::select('job_id', DB::expr('COUNT(*) as cnt'))->from('attachments')->where('job_id', 'IN', $ids)->and_where('uploaded', '>', 0)->and_where('folder', '<>', 'Signatures')->group_by('job_id')->execute()->as_array('job_id', 'cnt'); } else { $attachments = array(); } if (Group::current('allow_assign')) { $result = Database_Mongo::collection('submissions')->aggregate(array(array('$match' => array('job_key' => array('$in' => $ids), 'active' => 1)), array('$group' => array('_id' => '$job_key', 'count' => array('$sum' => 1))))); $submissions = array(); foreach (Arr::get($result, 'result', array()) as $value) { $submissions[$value['_id']] = $value['count']; } } if (isset($static['last_update'])) { $header[] = 'Last update'; } if (isset($static['last_submit'])) { $header[] = 'Last submit'; } if (isset($static['status']) && Group::current('show_all_jobs')) { $header[] = 'Job status'; } if (isset($static['types'])) { $header[] = 'Assigned works'; } if (isset($static['companies'])) { $header[] = 'Assigned companies'; } if (isset($static['ex'])) { $header[] = 'Previously assigned companies'; } if (isset($static['pending'])) { $header[] = 'Pending submissions'; } if (isset($static['attachments'])) { $header[] = 'Attachments'; } foreach (Columns::get_search() as $id => $type) { $header[] = Columns::get_name($id); } if ($action == 'excel') { $excel = new PHPExcel(); $sheet = $excel->getActiveSheet(); $sheet->setTitle('Search Results'); $sheet->fromArray($header, NULL, 'A1'); $i = 1; foreach (range('A', $sheet->getHighestDataColumn()) as $col) { $sheet->getColumnDimension($col)->setAutoSize(true); } $x = $attachments_list ? max(array_map('count', $attachments_list)) : 0; foreach (range(0, $x - 1) as $col) { $sheet->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex(count($header) + $col))->setWidth(14); } } else { $file = tmpfile(); fputcsv($file, $header); } foreach ($jobs as $ticket) { $row = array($ticket['_id']); if (isset($static['last_update'])) { $row[] = date('d-m-Y H:i', Arr::get($ticket, 'last_update', $ticket['created'])); } if (isset($static['last_submit'])) { $row[] = Arr::get($ticket, 'last_submit') ? date('d-m-Y H:i', $ticket['last_submit']) : ''; } if (isset($static['status']) && Group::current('show_all_jobs')) { $row[] = Arr::get(Enums::$statuses, Arr::get($ticket, 'status', 0), 'Unknown'); } if (isset($static['types'])) { if (Group::current('allow_assign')) { $row[] = implode(', ', array_intersect_key($types, Arr::get($ticket, 'assigned', array()))); } else { $row[] = implode(', ', array_intersect_key($types, array_filter(Arr::get($ticket, 'assigned', array()), function ($x) { return $x == User::current('company_id'); }))); } } if (isset($static['companies'])) { $row[] = implode(', ', array_intersect_key($companies, array_flip(Arr::get($ticket, 'assigned', array())))); } if (isset($static['ex'])) { $row[] = implode(', ', array_intersect_key($companies, array_flip(Arr::get($ticket, 'ex', array())))); } if (isset($static['pending'])) { $row[] = Arr::get($submissions, $ticket['_id']); } if (isset($static['attachments'])) { $row[] = Arr::get($attachments, $ticket['_id']); } foreach (Columns::get_search() as $id => $type) { $row[] = Arr::path($ticket, array('data', $id)) ? Columns::output($ticket['data'][$id], Columns::get_type($id), true) : ''; } if ($action == 'excel') { $i++; $sheet->fromArray($row, NULL, 'A' . $i); $x = count($row); if (isset($attachments_list[$ticket['_id']])) { $sheet->getRowDimension($i)->setRowHeight(80); } foreach (Arr::get($attachments_list, $ticket['_id'], array()) as $image) { if (!file_exists(DOCROOT . 'storage/' . $image . '.thumb')) { if (!file_exists(DOCROOT . 'storage/' . $image)) { continue; } $data = file_get_contents(DOCROOT . 'storage/' . $image); $er = error_reporting(0); $img = imagecreatefromstring($data); error_reporting($er); if (!$img) { continue; } $x = imagesx($img); $y = imagesy($img); $size = max($x, $y); $x = round($x / $size * 96); $y = round($y / $size * 96); $thumb = imagecreatetruecolor($x, $y); imagealphablending($thumb, false); imagesavealpha($thumb, true); imagecopyresampled($thumb, $img, 0, 0, 0, 0, $x, $y, imagesx($img), imagesy($img)); imagepng($thumb, DOCROOT . 'storage/' . $image . '.thumb', 9); } $data = file_get_contents(DOCROOT . 'storage/' . $image . '.thumb'); $img = imagecreatefromstring($data); $objDrawing = new PHPExcel_Worksheet_MemoryDrawing(); $objDrawing->setImageResource($img); $coord = PHPExcel_Cell::stringFromColumnIndex($x++); $objDrawing->setCoordinates($coord . $i); $objDrawing->setOffsetY(5); $objDrawing->setResizeProportional(true); $objDrawing->setRenderingFunction(PHPExcel_Worksheet_MemoryDrawing::RENDERING_PNG); $objDrawing->setMimeType(PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_DEFAULT); $objDrawing->setWorksheet($sheet); //$sheet->getCell($coord . $i)->setHyperlink(new PHPExcel_Cell_Hyperlink(URL::site('download/attachment/' . $image, 'http'), 'Show Image')); } } else { fputcsv($file, $row); } } if ($action == 'excel') { $name = tempnam(sys_get_temp_dir(), 'excel'); header('Content-type: application/xlsx'); header('Content-disposition: filename="SearchResults.xlsx"'); $writer = new PHPExcel_Writer_Excel2007($excel); $writer->save($name); readfile($name); unlink($name); } else { fseek($file, 0); header('Content-type: text/csv'); header('Content-disposition: filename="SearchResults.csv"'); fpassthru($file); fclose($file); } die; }
public function action_index() { $ids = array_keys(Arr::get($_POST, 'job', array())); if (!$ids) { throw new HTTP_Exception_404('Not found'); } $regs = DB::select('region_id')->from('user_regions')->where('user_id', '=', User::current('id'))->execute()->as_array('region_id', 'region_id'); $query = array(); if ($regs) { $query['region'] = array('$in' => array_values($regs)); } if (!Group::current('show_all_jobs')) { $query['$or'] = array(array('ex' => intval(User::current('company_id'))), array('companies' => intval(User::current('company_id')))); } $query['_id'] = array('$in' => $ids); $jobs = Database_Mongo::collection('jobs')->find($query); $static = array_flip(explode(',', Group::current('columns'))); $header = array('Ticket ID'); $types = DB::select('id', 'name')->from('job_types')->execute()->as_array('id', 'name'); $companies = DB::select('id', 'name')->from('companies')->execute()->as_array('id', 'name'); if ($ids) { $attachments = DB::select('job_id', DB::expr('COUNT(*) as cnt'))->from('attachments')->where('job_id', 'IN', $ids)->and_where('uploaded', '>', 0)->group_by('job_id')->execute()->as_array('job_id', 'cnt'); } else { $attachments = array(); } if (Group::current('allow_assign')) { $result = Database_Mongo::collection('submissions')->aggregate(array(array('$match' => array('job_key' => array('$in' => $ids), 'active' => 1)), array('$group' => array('_id' => '$job_key', 'count' => array('$sum' => 1))))); $submissions = array(); foreach (Arr::get($result, 'result', array()) as $value) { $submissions[$value['_id']] = $value['count']; } } if (isset($static['last_update'])) { $header[] = 'Last update'; } if (isset($static['last_submit'])) { $header[] = 'Last submit'; } if (isset($static['status']) && Group::current('show_all_jobs')) { $header[] = 'Job status'; } if (isset($static['types'])) { $header[] = 'Assigned works'; } if (isset($static['companies'])) { $header[] = 'Assigned companies'; } if (isset($static['pending'])) { $header[] = 'Pending submissions'; } if (isset($static['attachments'])) { $header[] = 'Attachments'; } foreach (Columns::get_search() as $id => $type) { $header[] = Columns::get_name($id); } $list = array(); $request = array(); foreach ($jobs as $job) { if (!isset($job['lat'])) { $request[$job['_id']] = Arr::path($job, 'data.8'); } } if ($request) { $coords = MapQuest::locate($request); foreach ($coords as $key => $value) { Database_Mongo::collection('jobs')->update(array('_id' => $key), array('$set' => array('lng' => $value['lng'], 'lat' => $value['lat']))); } } else { $coords = array(); } foreach ($jobs as $ticket) { if (isset($coords[$ticket['_id']])) { $ticket['lng'] = $coords[$ticket['_id']]['lng']; $ticket['lat'] = $coords[$ticket['_id']]['lat']; } if (!isset($ticket['lat'])) { continue; } $row = array($ticket['_id']); if (isset($static['last_update'])) { $row[] = date('d-m-Y H:i', Arr::get($ticket, 'last_update', $ticket['created'])); } if (isset($static['last_submit'])) { $row[] = Arr::get($ticket, 'last_submit') ? date('d-m-Y H:i', $ticket['last_submit']) : ''; } if (isset($static['status']) && Group::current('show_all_jobs')) { $row[] = Arr::get(Enums::$statuses, Arr::get($ticket, 'status', 0), 'Unknown'); } if (isset($static['types'])) { if (Group::current('allow_assign')) { $row[] = implode(', ', array_intersect_key($types, Arr::get($ticket, 'assigned', array()))); } else { $row[] = implode(', ', array_intersect_key($types, array_filter(Arr::get($ticket, 'assigned', array()), function ($x) { return $x == User::current('company_id'); }))); } } if (isset($static['companies'])) { $row[] = implode(', ', array_intersect_key($companies, array_flip(Arr::get($ticket, 'assigned', array())))); } if (isset($static['pending'])) { $row[] = Arr::get($submissions, $ticket['_id']); } if (isset($static['attachments'])) { $row[] = Arr::get($attachments, $ticket['_id']); } foreach (Columns::get_search() as $id => $type) { $row[] = Arr::path($ticket, array('data', $id)) ? Columns::output($ticket['data'][$id], Columns::get_type($id), true) : ''; } $row = array_combine($header, $row); $row['lat'] = $ticket['lat']; $row['lng'] = $ticket['lng']; $list[] = $row; } if (!$list) { throw new HTTP_Exception_404('Not found'); } DB::delete('maps')->where('expire', '<', time())->execute(); $ids = DB::select('map_id')->distinct(true)->from('maps')->execute()->as_array('map_id', 'map_id'); do { $id = Text::random('alnum', 32); } while (isset($ids[$id])); $expire = time() + 60 * 60 * 24 * 7; $query = DB::insert('maps', array('map_id', 'job_key', 'lng', 'lat', 'info', 'expire')); foreach ($list as $values) { $lat = $values['lat']; $lng = $values['lng']; unset($values['lng']); unset($values['lat']); $query->values(array($id, $values['Ticket ID'], $lng, $lat, json_encode($values), $expire)); } $query->execute(); $this->redirect('/map.html#' . $id); }
<?php if (isset($columns['attachments'])):?> <td class="hidden-xs"> <strong><?=Arr::get($attachments, $ticket['_id'])?></strong> <?php if (Group::current('allow_assign') && isset($ticket['download-by'])):?> <small><br/>Last download:<br/> <?=User::get($ticket['download-by'], 'login')?><br/> <?=Arr::get($companies, User::get($ticket['download-by'], 'company_id'))?> <?php if (isset($ticket['download-at'])):?> <br/><?=date('d-m-Y H:i', $ticket['download-at'])?> <?php endif;?> </small> <?php endif;?> </td> <?php endif;?> <?php foreach (Columns::get_search() as $id => $name): $value = Columns::output(Arr::path($ticket, 'data.'.$id), Columns::get_type($id));?> <td <?=strlen($value) > 100 ? 'class="shorten data-editable-cell"' : 'data-editable-cell'?>><?=$value?></td> <?php endforeach;?> <td class="table-buttons"> <?php if (Group::current('allow_forms') && !Arr::get($ticket, 'locked') && in_array(User::current('company_id'), Arr::get($ticket, 'assigned', array(), true))):?> <a href="<?=URL::base()?>search/form/<?=$ticket['_id']?>" class="btn btn-success col-xs-12" data-toggle="tooltip" data-placement="top"><span class="glyphicon glyphicon-list-alt"></span> Submit data</a> <?php endif;?> <a href="<?=URL::base()?>search/view/<?=$ticket['_id']?>" class="btn btn-info col-xs-12" data-toggle="tooltip" data-placement="top"><span class="glyphicon glyphicon-search"></span> View</a> <?php if (Group::current('allow_reports')):?> <a href="<?=URL::base()?>imex/reports?ticket=<?=$ticket['_id']?>" class="btn btn-warning col-xs-12" data-toggle="tooltip" data-placement="top"><span class="glyphicon glyphicon-list"></span> Reports</a> <a href="<?=URL::base()?>assign?ticket=<?=$ticket['_id']?>" class="btn btn-primary col-xs-12" data-toggle="tooltip" data-placement="top"><span class="glyphicon glyphicon-pencil"></span> Assign logs</a> <?php endif;?> <?php if (Group::current('allow_submissions')):?>
<th>Status</th> <th>Processed</th> <th>Company</th> <th>Location</th> <th>Column name</th> <th>Value</th> <th>Current value</th> <?php if (Group::current('allow_assign')):?> <th> </th> <?php endif;?> </tr> <?php foreach ($submissions as $submission): $name = Columns::get_name(substr($submission['key'], 5)); $type = Columns::get_type(substr($submission['key'], 5)); $value = Columns::output($submission['value'], $type); $current = Columns::output(Arr::path($job, 'data.' . substr($submission['key'], 5)), $type); ?> <tr class="<?=Arr::get($submission, 'active') ? ($submission['active'] > 0 ? 'bg-warning' : 'bg-success') : 'bg-danger'?>"> <td><?=date('d-m-Y H:i:s', $submission['update_time'])?></td> <td><?=User::get($submission['user_id'], 'login')?></td> <td><?=isset($submission['version']) ? 'Mobile app (' . ($submission['version'] ? : 'Unknown') . ')' : 'Web-app'?></td> <td><span class="glyphicon glyphicon-<?=Arr::get($submission, 'active') ? ($submission['active'] < 0 ? 'ok text-success' : 'edit text-info') : 'remove text-danger'?>"></span></td> <td><?=Arr::get($submission, 'process_time') ? date('d-m-Y H:i:s', $submission['process_time']) . ' by ' . User::get(Arr::get($submission, 'admin_id'), 'login') : ''?></td> <td><?=Arr::get($companies, User::get($submission['user_id'], 'company_id'))?></td> <td><?=Arr::get($submission, 'location') ? '<a target="_blank" href="https://www.google.com/maps/@' . $submission['location'] . ',19z">Location</a>' : ''?></td> <td><?=HTML::chars($name)?></td> <td class="<?=strlen($value) > 100 ? 'shorten' : ''?>"><?=$value?></td> <td class="<?=strlen($current) > 100 ? 'shorten' : ''?>"><?=$current?></td> <?php if (Group::current('allow_assign')):?> <td> <?php if (!Arr::get($submission, 'active')):?>
public function action_index() { $tables = DB::select()->from('reports')->execute()->as_array('id', 'name'); $geo = false; $attachments = false; if ($_POST) { $id = intval(Arr::get($_POST, 'id')); if (!isset($tables[$id])) { throw new HTTP_Exception_404('Not found'); } $query = array('report_id' => $id); if (!Group::current('show_all_jobs')) { $query['company'] = User::current('company_id'); } $columns = DB::select('id', 'name', 'type', 'visible')->from('report_columns')->where('report_id', '=', $query['report_id'])->and_where('visible', '<>', 'hidden')->execute()->as_array('id'); foreach ($columns as $column) { if (isset($_POST[$column['id']])) { $key = $column['id']; $type = $column['type']; if (isset($_POST[$key]['from'])) { $query[$key]['$gte'] = Columns::parse($_POST[$key]['from'], $type); } if (isset($_POST[$key]['to'])) { $query[$key]['$lte'] = Columns::parse($_POST[$key]['to'], $type); } if (isset($_POST[$key]['value'])) { $values = explode('|', $_POST[$key]['value']); foreach ($values as $value) { if ($value) { $query[$key]['$in'][] = new MongoRegex('/' . $value . '/i'); } } } } } $query['expires'] = time() + 3600; Database_Mongo::collection('search')->insert($query); header('Content-type: application/json'); die(json_encode(array('success' => true, 'id' => strval($query['_id'])))); } elseif (Arr::get($_GET, 'id')) { $query = Database_Mongo::collection('search')->findOne(array('_id' => new MongoId($_GET['id']))); if (!$query) { $this->redirect('reports/forms'); } $columns = DB::select('id', 'name', 'type', 'visible')->from('report_columns')->where('report_id', '=', $query['report_id'])->and_where('visible', '<>', 'hidden')->execute()->as_array('id'); unset($query['_id']); unset($query['expires']); $result = Database_Mongo::collection('reports')->find($query); Pager::$count = $result->count(); $result->skip(Pager::offset())->limit(Pager::limit()); $reports = array(); foreach ($result as $report) { $id = strval($report['_id']); $data = array('id' => $id, 'attachment' => Arr::get($report, 'attachment', 'Unknown file'), 'attachment_id' => Arr::get($report, 'attachment_id', 0), 'colors' => Arr::get($report, 'colors', array())); foreach ($columns as $key => $column) { $data[$key] = Arr::get($report, $key, ''); } if (isset($report['geo'])) { $geo = true; $data['geo'] = $report['geo']; } if (Arr::get($report, 'attachments')) { $attachments = true; $data['attachments'] = $report['attachments']; } $reports[$id] = $data; } if (isset($_GET['export'])) { $header = array('Name'); foreach ($columns as $column) { $header[] = $column['name']; } $data = array($header); $ids = isset($_GET['ids']) && !isset($_GET['all']) ? array_flip(explode(',', $_GET['ids'])) : array(); foreach ($reports as $report) { if (!$ids || isset($ids[$report['attachment_id']])) { $row = array($report['attachment']); foreach ($columns as $column) { $row[] = Arr::get($report, $column['id']) ? Columns::output($report[$column['id']], $column['type'], true) : ''; } $data[] = $row; } } switch ($_GET['export']) { case 'excel': $excel = new PHPExcel(); $sheet = $excel->getActiveSheet(); $sheet->setTitle('Search Results'); $sheet->fromArray($data, NULL, 'A1'); foreach (range('A', $sheet->getHighestDataColumn()) as $col) { $sheet->getColumnDimension($col)->setAutoSize(true); } $name = tempnam(sys_get_temp_dir(), 'excel'); header('Content-type: application/xlsx'); header('Content-disposition: filename="' . Arr::get($tables, $query['report_id'], 'Unknown') . '.xlsx"'); $writer = new PHPExcel_Writer_Excel2007($excel); $writer->save($name); readfile($name); unlink($name); break; default: header('Content-type: text/csv'); header('Content-disposition: attachment;filename="' . Arr::get($tables, $query['report_id'], 'Unknown') . '.csv"'); $file = fopen('php://output', 'w'); foreach ($data as $row) { fputcsv($file, $row); } fclose($file); break; } die; } } else { $columns = array(); $reports = array(); } $view = View::factory('Reports/Forms')->set('geo', $geo)->set('attachments', $attachments)->bind('tables', $tables)->bind('reports', $reports)->bind('filters', $query)->bind('columns', $columns); $this->response->body($view); }
public function action_index() { $start = Arr::get($_GET, 'start') ? strtotime($_GET['start']) : strtotime('first day of this month'); $end = Arr::get($_GET, 'end') ? strtotime($_GET['end']) + 86399 : time(); $query = array('financial_time' => isset($_GET['excel']) ? array('$gt' => 0) : array('$exists' => 1), 'update_time' => array('$gt' => intval($start), '$lt' => intval($end))); if (Arr::get($_GET, 'app-start')) { $query['process_time']['$gt'] = strtotime($_GET['app-start']); } if (Arr::get($_GET, 'app-end')) { $query['process_time']['$lt'] = strtotime($_GET['app-end']) + 86399; } if (Arr::get($_GET, 'fin-start')) { $query['financial_time']['$gt'] = strtotime($_GET['fin-start']); } if (Arr::get($_GET, 'fin-end')) { $query['financial_time']['$lt'] = strtotime($_GET['fin-end']) + 86399; } if (Group::current('allow_assign')) { $companies = DB::select('id', 'name')->from('companies')->order_by('name', 'asc')->execute()->as_array('id', 'name'); } if (!Group::current('allow_assign') || Arr::get($_GET, 'company')) { if (Group::current('allow_assign')) { $company = $_GET['company']; if (!is_array($company)) { $company = explode(',', $company); } $company = array_map('intval', $company); } else { $company = array(User::current('company_id')); } $query['user_id'] = array('$in' => DB::select('id')->from('users')->where('company_id', 'IN', $company)->execute()->as_array(NULL, 'id')); } $jobs = array(); if (Arr::get($_GET, 'ticket')) { $tickets = explode(',', $_GET['ticket']); $q = array(); foreach ($tickets as $ticket) { $ticket = preg_replace('/[^a-z0-9]/i', '', strval($ticket)); if (!$ticket) { continue; } if (preg_match('/^T1W[0-9]{12}$/', $ticket)) { $q[] = $ticket; } else { $q[] = new MongoRegex('/.*' . $ticket . '.*/i'); } } if (count($q) > 1) { $jobs['_id'] = array('$in' => $q); } elseif ($q) { $jobs['_id'] = $q[0]; } } if (Arr::get($_GET, 'fsa')) { $values = is_array($_GET['fsa']) ? $_GET['fsa'] : explode(',', $_GET['fsa']); $jobs['data.12'] = count($values) > 1 ? array('$in' => array_values($values)) : current($values); } if (Arr::get($_GET, 'fsam')) { $values = is_array($_GET['fsam']) ? $_GET['fsam'] : explode(',', $_GET['fsam']); $jobs['data.13'] = count($values) > 1 ? array('$in' => array_values($values)) : current($values); } if (Arr::get($_GET, 'fda')) { $values = is_array($_GET['fda']) ? $_GET['fda'] : explode(',', $_GET['fda']); $jobs['data.14'] = count($values) > 1 ? array('$in' => array_values($values)) : current($values); } if (Arr::get($_GET, 'address')) { $jobs['data.8'] = new MongoRegex('/.*' . strval($_GET['address']) . '.*/mi'); } if ($jobs) { if (count($jobs) == 1 && isset($jobs['_id'])) { $query['job_key'] = $jobs['_id']; } else { $query['job_key'] = array('$in' => Database_Mongo::collection('jobs')->distinct('_id', $jobs)); } } $sort = array('job_key' => 1); if (!Arr::get($_GET, 'sort')) { $_GET['sort'] = array('-submission'); } foreach ($_GET['sort'] as $s) { $dir = substr($s, 0, 1) == '-' ? -1 : 1; $s = substr($s, 1); switch ($s) { case 'submission': $sort['update_time'] = $dir; break; case 'approval': $sort['process_time'] = $dir; break; case 'financial': $sort['financial_time'] = $dir; break; } } $result = Database_Mongo::collection('submissions')->find($query)->sort($sort); $submissions = array(); $users = array(); $jobs = array(); $keys = array('region' => 1, 'data.8' => 1, 'data.9' => 1, 'data.14' => 1); foreach ($result as $submission) { $jobs[$submission['job_key']] = 1; $keys[$submission['key']] = 1; $submissions[$submission['job_key']][] = $submission; $users[$submission['user_id']] = 1; } $result = Database_Mongo::collection('jobs')->find(array('_id' => array('$in' => array_keys($jobs))), $keys); $jobs = array(); foreach ($result as $job) { $jobs[$job['_id']] = $job; } if ($users) { User::get(array_keys($users)); } $rates = array(); $result = DB::select()->from('rates')->execute(); foreach ($result as $row) { $rates[$row['company_id']][$row['region_id']][$row['column_id']] = $row['rate']; } $columns = Columns::get_financial(); $approved = array(); $duplicates = array(); $discr = array(); $partial = array(); $full = array(); $skip = array(); if (Group::current('allow_assign') && isset($_GET['approve']) && Arr::get($_GET, 'company') && count($_GET['company']) == 1) { $rates = Arr::get($rates, $_GET['company'][0], array()); foreach ($submissions as $job => $list) { $region = $jobs[$job]['region']; $data = array(); $partial_fl = false; $full_fl = true; $dup_fl = false; $discr_fl = false; $skip_fl = false; foreach ($list as $submission) { $data[$submission['key']][] = $submission; } foreach ($data as $key => $values) { $key = substr($key, 5); $rate = isset($rates[$region][$key]) ? $rates[$region][$key] : (isset($rates[0][$key]) ? $rates[0][$key] : 0); $value = array_shift($values); if (count($values)) { $dup_fl = true; $full_fl = false; } elseif ($value['value'] != Arr::path($jobs, $job . '.data.' . $key)) { $discr_fl = true; $full_fl = false; } elseif (!$rate) { $skip_fl = true; $full_fl = false; } elseif (!$value['financial_time']) { $approved[] = array('id' => $value['_id'], 'rate' => $rate, 'paid' => min(floatval($value['value']), Arr::get($columns, $key))); $partial_fl = true; } } if ($partial_fl) { if ($full_fl) { $full[$job] = 1; } else { $partial[$job] = 1; } } if ($skip_fl) { $skip[$job] = 1; } if ($dup_fl) { $duplicates[$job] = 1; } if ($discr_fl) { $discr[$job] = 1; } $submissions[$job] = $data; } $time = time(); foreach ($approved as $value) { Database_Mongo::collection('submissions')->update(array('_id' => $value['id']), array('$set' => array('paid' => $value['paid'], 'rate' => $value['rate'], 'financial_time' => $time))); } $count = count($jobs); $jobs = Database_Mongo::collection('jobs')->find(array('_id' => array('$in' => array_keys($jobs)))); foreach ($jobs as $job) { Utils::calculate_financial($job); } Messages::save(sprintf('%d/%d tickets were successfully approved.', count($full), $count), 'success'); if ($partial) { Messages::save(sprintf('%d tickets were partially approved.', count($partial)), 'warning'); } if ($discr) { Messages::save(sprintf('%d tickets contain discrepancies.', count($discr)), 'danger'); } if ($duplicates) { Messages::save(sprintf('%d tickets contain duplicates.', count($duplicates)), 'danger'); } if ($skip) { Messages::save(sprintf('%d tickets contain submissions with unknown rates.', count($skip)), 'danger'); } $this->redirect($this->request->uri() . URL::query(array('approve' => NULL))); } elseif (isset($_GET['export'])) { $discr = isset($_GET['discrepancy']); header('Content-type: text/csv'); header('Content-disposition: filename="Submissions.' . date('Ymd', $start) . '-' . date('Ymd', $end) . '.' . date('YmdHi', time()) . '.csv"'); $file = tmpfile(); $headers = array('Tickets ID', 'Submission Date', 'Approval Date', 'User'); if (Group::current('allow_assign')) { $headers[] = 'Company'; } $headers[] = 'Column'; $headers[] = 'Value'; $keys = array(); fputcsv($file, $headers); foreach ($submissions as $job => $list) { foreach ($list as $submission) { if (!$discr || Arr::path($jobs, $job . '.' . $submission['key']) != $submission['value']) { $keys[$submission['key']] = 1; $key = substr($submission['key'], 5); $data = array($job, date('d-m-Y H:i', $submission['update_time']), Arr::get($submission, 'process_time') ? date('d-m-Y H:i', $submission['process_time']) : '', User::get($submission['user_id'], 'login')); if (Group::current('allow_assign')) { $data[] = Arr::get($companies, User::get($submission['user_id'], 'company_id'), 'Unknown'); } $data[] = Columns::get_name($key); $data[] = Columns::output($submission['value'], Columns::get_type($key), true); fputcsv($file, $data); } } } fseek($file, 0); fpassthru($file); fclose($file); die; } elseif (isset($_GET['excel'])) { $doc = PHPExcel_IOFactory::load(DOCROOT . 'financial.template.xlsx'); $sheet = $doc->getSheet(); $sheet->setTitle(date('d-m-Y', $start) . ' - ' . date('d-m-Y', $end)); $s = date('M Y', $start); $e = date('M Y', $end); if ($s == $e) { $month = $s; } else { $month = $s . ' - ' . $e; } $map = array('G' => '190', 'H' => '191', 'I' => '192', 'J' => '193', 'K' => '194', 'L' => '195', 'M' => '196', 'N' => '197', 'O' => '198', 'P' => '199', 'Q' => '200', 'R' => '201', 'S' => '202', 'T' => '203', 'U' => '204', 'V' => '205', 'W' => '206', 'X' => '207', 'Y' => '208', 'Z' => '43', 'AA' => '257'); $i = 10; $total = array(); $amount = array(); $users = array(); if (count($submissions)) { foreach (array_merge($map, array('AC' => 0, 'AD' => 0)) as $column => $key) { $sheet->setCellValue($column . '7', '=SUM(' . $column . '11:' . $column . (count($submissions) + 10) . ')'); } $styleArray = array('borders' => array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THIN))); $sheet->getStyle('B11:AD' . (count($submissions) + 10))->applyFromArray($styleArray); } foreach ($submissions as $job => $list) { $job = Database_Mongo::collection('jobs')->findOne(array('_id' => $job)); $data = Arr::get($job, 'data'); $inst_min = false; $inst_max = false; $app_min = false; $app_max = false; $result = array(); $rate = array(); foreach ($list as $submission) { $users[$submission['user_id']] = 1; $inst = $submission['update_time']; if ($inst_min === false || $inst_min > $inst) { $inst_min = $inst; } if ($inst_max === false || $inst_max < $inst) { $inst_max = $inst; } $app = Arr::get($submission, 'process_time', false); if ($app_min === false && $app !== false || $app_min > $app) { $app_min = $app; } if ($app_max === false && $app !== false || $app_max < $app) { $app_max = $app; } $key = substr($submission['key'], 5); $result[$key] = $submission['paid']; $rate[$key] = $submission['rate']; } $sum = 0; foreach ($result as $key => $value) { $sum += $value * $rate[$key]; $total[$key] = Arr::get($total, $key, 0) + $value * $rate[$key]; $amount[$key] = Arr::get($amount, $key, 0) + $value; } $i++; $inst_min = date('d-m-Y', $inst_min); $inst_max = date('d-m-Y', $inst_max); $app_min = date('d-m-Y', $app_min); $app_max = date('d-m-Y', $app_max); $sheet->setCellValue('B' . $i, $inst_min == $inst_max ? $inst_min : $inst_min . ' - ' . $inst_max)->setCellValue('C' . $i, $app_min == $app_max ? $app_min : $app_min . ' - ' . $app_max)->setCellValue('D' . $i, $job['_id'])->setCellValue('E' . $i, Arr::get($data, 8))->setCellValue('F' . $i, Arr::get($data, 14))->setCellValue('AC' . $i, $sum); foreach ($map as $key => $value) { $sheet->setCellValue($key . $i, Arr::get($result, $value) ? $result[$value] : ''); } } foreach ($map as $key => $value) { $sheet->setCellValue($key . '10', Arr::get($amount, $value) ? $total[$value] / $amount[$value] : ''); } if ($users) { $companies = DB::select('name')->from('companies')->where('id', 'IN', DB::select('company_id')->distinct(true)->from('users')->where('id', 'IN', array_keys($users)))->execute()->as_array(NULL, 'name'); } else { $companies = array('None'); } $sheet->setCellValue('D2', implode(', ', $companies))->setCellValue('D3', $month); header('Content-type: application/xlsx'); header('Content-disposition: filename="Report.xlsx"'); $name = tempnam(sys_get_temp_dir(), 'excel'); $writer = new PHPExcel_Writer_Excel2007($doc); $writer->setPreCalculateFormulas(true); $writer->save($name); readfile($name); unlink($name); die; } $discrepancies = array(); foreach ($submissions as $job => $list) { $fl = false; foreach ($list as $submission) { if (Arr::path($jobs, $job . '.' . $submission['key']) != $submission['value']) { $fl = true; break; } } if (!$fl) { $discrepancies[$job] = 1; } } $view = View::factory("Reports/Financial")->set('approve_all', $start > 0 && date('m', $start) == date('m', $end) && Arr::get($_GET, 'company') && count($_GET['company']) == 1 && !Arr::get($_GET, 'fin-start'))->bind('companies', $companies)->bind('submissions', $submissions)->bind('discrepancies', $discrepancies)->bind('columns', $columns)->bind('jobs', $jobs)->bind('rates', $rates); $this->response->body($view); }
<th class="col-xs-1">Date</th> <th class="col-xs-1">User</th> <th class="col-xs-1">File name</th> <?php foreach ($reports as $id => $name):?> <th class="col-xs-1"><?=HTML::chars($name)?></th> <?php endforeach;?> <th>Columns:</th> </tr> <?php foreach ($tickets as $ticket):?> <tr class="text-center super yellow <?=$ticket['discr'] ? 'discrepancy' . (isset($_GET['discrepancy']) ? ' hidden' : '') : ''?>"> <td><a href="<?=URL::base() . 'search/view/' . $ticket['job_key']?>"><?=$ticket['job_key']?></a></td> <td nowrap="nowrap"><?=date('d-m-Y H:i', $ticket['update_time'])?></td> <td><?=User::get(Arr::get($ticket, 'user_id'), 'login') ? : 'Unknown'?></td> <td><a href="<?=URL::base() . 'imex/discrepancies?file=' . urlencode($ticket['filename'])?>"><?=HTML::chars($ticket['filename'])?></a></td> <?php foreach ($reports as $key => $name):?> <td><?=Columns::output(Arr::path($ticket, 'static.'.$key), Columns::get_type($key))?></td> <?php endforeach;?> <td> <table class="table subtable"> <tr class="same-yellow"> <th>Column name</th> <th>Old value</th> <th>New value</th> <th>Current value</th> </tr> <?php foreach($ticket['data'] as $id => $value): $date = Columns::get_type($id) == 'date';?> <tr class="submission <?=$value['old_value'] != $ticket['current'][$id] ? 'rose' : 'same-yellow' . (isset($_GET['discrepancy']) ? ' hidden' : '')?>"> <td><?=HTML::chars(Columns::get_name($id));?></td> <td><?=HTML::chars($date ? date("d-m-Y H:i", $value['old_value'] ? : 0) : $value['old_value'])?></td> <td><?=HTML::chars($date ? date("d-m-Y H:i", $value['new_value'] ? : 0) : $value['new_value'])?></td> <td><?=HTML::chars($date ? date("d-m-Y H:i", $ticket['current'][$id] ? : 0) : $ticket['current'][$id])?></td>
<?php foreach ($columns as $key => $values):?> <tr id="fields-<?=crc32($key)?>" class="custom-jobs-container hidden"> <?php $tdIndex=0;?> <td colspan="2"> <label><?=$key?>:</label> <div class="width100"> <table class="flatten-sub-table width100"> <?php foreach ($values as $id => $value): $index = 0; $status = Arr::path($job_values, 'data' . intval($id) . '.status'); $old = Arr::path($job_values, 'data' . intval($id) . '.value'); ?> <?php if (0 == $index++ % 2) :?> <tr> <?php endif; ?> <td> <div class="status-cell <?=$status === -1 ? 'bg-success has-success' : ($status === 1 ? 'bg-warning has-warning' : '')?>"> <label class=""><?=$value?>:</label> <?php if ($old):?> <br/><label class="old_value control-label <?=strlen($old) > 100 ? 'shorten' : ''?> " >Last submitted value: <span class=""><?=Columns::output($old, Columns::get_type(intval($id)))?></span></label> <?php endif;?> <p class="column-value"> <?=Columns::input('data-' . crc32($key) . '[' . $id . ']', NULL, Columns::get_type(intval($id)), $id == 242 ? Arr::path($job, 'data.242') : '', '', Arr::path(Form::$required, array($key, $id)))?> </p> </div> </td> <?php if (0 == $index % 2) :?> </tr> <?php endif; ?> <?php endforeach;?> </table> </div> </td>
<td><input type="checkbox" class="select-reports checkbox" data-id="<?=$report['attachment_id']?>"/></td> <td><a href="<?=URL::base()?>download/attachment/<?=$report['attachment_id']?>"><?=$report['attachment']?></a></td> <?php if ($geo):?> <td> <?php if (Arr::get($report, 'geo')):?> <a target="_blank" href="https://www.google.com/maps/@<?=$report['geo']?>,19z">View on map</a> <?php else:?> <?php endif;?> </td> <?php endif;?> <?php foreach ($columns as $column):?> <td <?=isset($report['colors'][$column['id']]) ? 'style="background-color: ' . $report['colors'][$column['id']] . ';"' : ''?> <?=Group::current('edit_custom_forms') && $column['visible'] == 'write' ? 'class="editable-form-cell" data-type="' . $column['type'] . '" data-guid="' . $column['id'] . '"' : ''?>> <?=Arr::get($report, $column['id']) ? Columns::output($report[$column['id']], $column['type']) : ' '?> </td> <?php endforeach;?> <?php if ($attachments):?> <td> <?php $i = 0; foreach (Arr::get($report, 'attachments', array()) as $attachment): if ($i++ == 2):?> <div class="popover-block"> <?php endif;?> <a href="<?=URL::base()?>download/attachment/<?=$attachment?>"><img src="<?=URL::base()?>download/thumb/<?=$attachment?>" /></a> <?php endforeach; if ($i > 2) echo '</div>';?> </td> <?php endif;?> </tr> <?php endforeach; else:?>
<td colspan="3"> <?php if ($history['update_type'] == 2):?> <table class="table subtable"> <tr> <th>Name</th> <th>Old value:</th> <th>New value:</th> <th>Current value</th> </tr> <?php foreach($history['data'] as $id => $value): $type = Columns::get_type($id);?> <tr class="same-yellow"> <td><?=HTML::chars(Columns::get_name($id))?></td> <td <?=strlen($value['old_value']) > 100 ? 'class="shorten"' : ''?>><?=Columns::output($value['old_value'], $type)?></td> <td <?=strlen($value['new_value']) > 100 ? 'class="shorten"' : ''?>><?=Columns::output($value['new_value'], $type)?></td> <td <?=strlen(Arr::get($job['data'], $id)) > 100 ? 'class="shorten"' : ''?>><?=Columns::output(Arr::get($job['data'], $id), $type)?></td> </tr> <?php endforeach;?> </table> <?php else:?> N/A <?php endif;?> </td> </tr> <?php endforeach;?> </table> </div> <?php endif;?> </div> <!-- tabs--> <ul class="nav nav-tabs status-filter upsidedown view-tab-header">